Skip to content

Commit

Permalink
add initial example
Browse files Browse the repository at this point in the history
  • Loading branch information
amk221 committed Sep 15, 2021
1 parent e047ace commit 24bb42d
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/components/my-component.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<button type="button" {{on "click" this.check}}>
check
</button>
11 changes: 11 additions & 0 deletions app/components/my-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';

export default class MyComponent extends Component {
@action
check() {
if (true) { // Some condition
throw new Error('check failed');
}
}
}
1 change: 1 addition & 0 deletions app/components/my-other-component.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
11 changes: 11 additions & 0 deletions app/components/my-other-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Component from '@glimmer/component';

export default class MyOtherComponent extends Component {
constructor() {
super(...arguments);

if (true) { // Some condition
throw new Error('check failed');
}
}
}
31 changes: 31 additions & 0 deletions tests/integration/components/my-component-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, click, setupOnerror, resetOnerror } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | my-component', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
setupOnerror((error) => {
if (error.message.match('check failed')) {
assert.step('asserts correct usage of component');
return;
}

throw error;
});
});

hooks.afterEach(function () {
resetOnerror();
});

test('it throws an error if check fails', async function (assert) {
await render(hbs`<MyComponent />`);

await click('button');

assert.verifySteps(['asserts correct usage of component']);
});
});
29 changes: 29 additions & 0 deletions tests/integration/components/my-other-component-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, setupOnerror, resetOnerror } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | my-other-component', function (hooks) {
setupRenderingTest(hooks);

hooks.beforeEach(function (assert) {
setupOnerror((error) => {
if (error.message.match('check failed')) {
assert.step('asserts correct usage of component');
return;
}

throw error;
});
});

hooks.afterEach(function () {
resetOnerror();
});

test('it throws an error if check fails', async function (assert) {
await render(hbs`<MyOtherComponent />`);

assert.verifySteps(['asserts correct usage of component']);
});
});

0 comments on commit 24bb42d

Please sign in to comment.