Skip to content

Commit 24bb42d

Browse files
committed
add initial example
1 parent e047ace commit 24bb42d

File tree

6 files changed

+86
-0
lines changed

6 files changed

+86
-0
lines changed

app/components/my-component.hbs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<button type="button" {{on "click" this.check}}>
2+
check
3+
</button>

app/components/my-component.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Component from '@glimmer/component';
2+
import { action } from '@ember/object';
3+
4+
export default class MyComponent extends Component {
5+
@action
6+
check() {
7+
if (true) { // Some condition
8+
throw new Error('check failed');
9+
}
10+
}
11+
}

app/components/my-other-component.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{yield}}

app/components/my-other-component.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Component from '@glimmer/component';
2+
3+
export default class MyOtherComponent extends Component {
4+
constructor() {
5+
super(...arguments);
6+
7+
if (true) { // Some condition
8+
throw new Error('check failed');
9+
}
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'ember-qunit';
3+
import { render, click, setupOnerror, resetOnerror } from '@ember/test-helpers';
4+
import { hbs } from 'ember-cli-htmlbars';
5+
6+
module('Integration | Component | my-component', function (hooks) {
7+
setupRenderingTest(hooks);
8+
9+
hooks.beforeEach(function (assert) {
10+
setupOnerror((error) => {
11+
if (error.message.match('check failed')) {
12+
assert.step('asserts correct usage of component');
13+
return;
14+
}
15+
16+
throw error;
17+
});
18+
});
19+
20+
hooks.afterEach(function () {
21+
resetOnerror();
22+
});
23+
24+
test('it throws an error if check fails', async function (assert) {
25+
await render(hbs`<MyComponent />`);
26+
27+
await click('button');
28+
29+
assert.verifySteps(['asserts correct usage of component']);
30+
});
31+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'ember-qunit';
3+
import { render, setupOnerror, resetOnerror } from '@ember/test-helpers';
4+
import { hbs } from 'ember-cli-htmlbars';
5+
6+
module('Integration | Component | my-other-component', function (hooks) {
7+
setupRenderingTest(hooks);
8+
9+
hooks.beforeEach(function (assert) {
10+
setupOnerror((error) => {
11+
if (error.message.match('check failed')) {
12+
assert.step('asserts correct usage of component');
13+
return;
14+
}
15+
16+
throw error;
17+
});
18+
});
19+
20+
hooks.afterEach(function () {
21+
resetOnerror();
22+
});
23+
24+
test('it throws an error if check fails', async function (assert) {
25+
await render(hbs`<MyOtherComponent />`);
26+
27+
assert.verifySteps(['asserts correct usage of component']);
28+
});
29+
});

0 commit comments

Comments
 (0)