Skip to content

Commit 2073f79

Browse files
authored
Merge pull request #2221 from ember-learn/update-helper-tests
Update helper test docs to follow RFC 0785
2 parents c3e2595 + 7cb5c87 commit 2073f79

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

guides/release/testing/test-types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module('Unit | Service | flash-messages', function(hooks) {
9090
});
9191
```
9292

93-
By calling `setupTest()`, you gain access to a few things. First is Ember's [Dependency Injection](../../applications/dependency-injection/) system. In short, you can [look up](https://api.emberjs.com/ember/release/classes/ApplicationInstance/methods/lookup?anchor=lookup) anything in your application, with a little help from `this.owner`. Second, you gain access to some common utility functions, `this.get()` and `this.set()`, in your tests. Finally, you can use `pauseTest()` to [debug your tests](../#toc_how-to-debug-tests).
93+
By calling `setupTest()`, you gain access to a few things. First is Ember's [Dependency Injection](../../applications/dependency-injection/) system. In short, you can [look up](https://api.emberjs.com/ember/release/classes/ApplicationInstance/methods/lookup?anchor=lookup) anything in your application, with a little help from `this.owner`. Also, you can use `pauseTest()` to [debug your tests](../#toc_how-to-debug-tests).
9494

9595

9696
## Rendering Tests
@@ -147,7 +147,7 @@ Here are more examples where rendering tests are ideal:
147147

148148
In order for rendering tests to work, you must call [`setupRenderingTest()`](https://github.com/emberjs/ember-qunit#setup-rendering-tests) and pass the `hooks` object.
149149

150-
What does `setupRenderingTest()` do? First, it uses `setupTest()` behind the scenes. Just like in [Unit Tests](../test-types/#toc_what-to-watch-out-for), you have access to `this.owner`, `this.get()`, `this.set()`, and `pauseTest()`.
150+
What does `setupRenderingTest()` do? First, it uses `setupTest()` behind the scenes. Just like in [Unit Tests](../test-types/#toc_what-to-watch-out-for), you have access to `this.owner` and `pauseTest()`.
151151

152152
In addition, `setupRenderingTest()` allows Ember's renderer to use helpers for rendering and DOM interaction, such as `render`, `click`, and `fillIn`. You can also use `this.element` to access the DOM element that results from `render`.
153153

guides/release/testing/testing-helpers.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,18 @@ import { module, test } from 'qunit';
5656
import { setupRenderingTest } from 'my-app-name/tests/helpers';
5757
import { render } from '@ember/test-helpers';
5858
import { hbs } from 'ember-cli-htmlbars';
59+
import { trackedObject } from '@ember/reactive/collections';
5960

6061
module('Integration | Helper | format currency', function(hooks) {
6162
setupRenderingTest(hooks);
6263

6364
test('formats 199 with $ as currency sign', async function(assert) {
64-
this.set('value', 199);
65-
this.set('sign', '$');
65+
const data = trackedObject({
66+
value: 199,
67+
sign: '$',
68+
});
6669

67-
await render(hbs`{{format-currency value sign=sign}}`);
70+
await render(hbs`{{format-currency data.value sign=data.sign}}`);
6871

6972
assert.equal(this.element.textContent.trim(), '$1.99');
7073
});
@@ -76,21 +79,25 @@ We can now also properly test if a helper will respond to property changes.
7679
```javascript {data-filename=tests/integration/helpers/format-currency-test.js}
7780
import { module, test } from 'qunit';
7881
import { setupRenderingTest } from 'my-app-name/tests/helpers';
79-
import { render } from '@ember/test-helpers';
82+
import { render, rerender } from '@ember/test-helpers';
8083
import { hbs } from 'ember-cli-htmlbars';
8184

8285
module('Integration | Helper | format currency', function(hooks) {
8386
setupRenderingTest(hooks);
8487

8588
test('formats 199 with $ as currency sign', async function(assert) {
86-
this.set('value', 199);
87-
this.set('sign', '$');
89+
const data = trackedObject({
90+
value: 199,
91+
sign: '$',
92+
});
8893

89-
await render(hbs`{{format-currency value sign=sign}}`);
94+
await render(hbs`{{format-currency data.value sign=data.sign}}`);
9095

9196
assert.equal(this.element.textContent.trim(), '$1.99');
9297

93-
this.set('sign', '');
98+
data.sign = '';
99+
100+
await rerender();
94101

95102
assert.equal(this.element.textContent.trim(), '€1.99', 'Value is formatted with €');
96103
});

0 commit comments

Comments
 (0)