From 24bb42d2ba3d68bd0381cd639385e43a4bf1102d Mon Sep 17 00:00:00 2001 From: Andrew Kirwin Date: Wed, 15 Sep 2021 09:47:07 +0100 Subject: [PATCH] add initial example --- app/components/my-component.hbs | 3 ++ app/components/my-component.js | 11 +++++++ app/components/my-other-component.hbs | 1 + app/components/my-other-component.js | 11 +++++++ .../components/my-component-test.js | 31 +++++++++++++++++++ .../components/my-other-component-test.js | 29 +++++++++++++++++ 6 files changed, 86 insertions(+) create mode 100644 app/components/my-component.hbs create mode 100644 app/components/my-component.js create mode 100644 app/components/my-other-component.hbs create mode 100644 app/components/my-other-component.js create mode 100644 tests/integration/components/my-component-test.js create mode 100644 tests/integration/components/my-other-component-test.js diff --git a/app/components/my-component.hbs b/app/components/my-component.hbs new file mode 100644 index 0000000..05d67a6 --- /dev/null +++ b/app/components/my-component.hbs @@ -0,0 +1,3 @@ + diff --git a/app/components/my-component.js b/app/components/my-component.js new file mode 100644 index 0000000..38f562b --- /dev/null +++ b/app/components/my-component.js @@ -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'); + } + } +} diff --git a/app/components/my-other-component.hbs b/app/components/my-other-component.hbs new file mode 100644 index 0000000..fb5c4b1 --- /dev/null +++ b/app/components/my-other-component.hbs @@ -0,0 +1 @@ +{{yield}} \ No newline at end of file diff --git a/app/components/my-other-component.js b/app/components/my-other-component.js new file mode 100644 index 0000000..6a1e3db --- /dev/null +++ b/app/components/my-other-component.js @@ -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'); + } + } +} diff --git a/tests/integration/components/my-component-test.js b/tests/integration/components/my-component-test.js new file mode 100644 index 0000000..639d683 --- /dev/null +++ b/tests/integration/components/my-component-test.js @@ -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``); + + await click('button'); + + assert.verifySteps(['asserts correct usage of component']); + }); +}); diff --git a/tests/integration/components/my-other-component-test.js b/tests/integration/components/my-other-component-test.js new file mode 100644 index 0000000..9c1ce8b --- /dev/null +++ b/tests/integration/components/my-other-component-test.js @@ -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``); + + assert.verifySteps(['asserts correct usage of component']); + }); +});