@@ -71,8 +71,6 @@ module('Integration | Component | pretty-color', function(hooks) {
71
71
setupRenderingTest (hooks);
72
72
73
73
test (' should change colors' , async function (assert ) {
74
- assert .expect (1 );
75
-
76
74
// set the outer context to red
77
75
this .set (' colorValue' , ' red' );
78
76
@@ -102,8 +100,6 @@ module('Integration | Component | pretty-color', function(hooks) {
102
100
setupRenderingTest (hooks);
103
101
104
102
test (' it renders' , async function (assert ) {
105
- assert .expect (2 );
106
-
107
103
// set the outer context to red
108
104
this .set (' colorValue' , ' red' );
109
105
@@ -129,8 +125,6 @@ module('Integration | Component | pretty-color', function(hooks) {
129
125
setupRenderingTest (hooks);
130
126
131
127
test (' it renders' , async function (assert ) {
132
- assert .expect (2 );
133
-
134
128
this .set (' colorValue' , ' orange' );
135
129
136
130
await render (hbs` <PrettyColor @name={{this.colorValue}} />` );
@@ -189,8 +183,6 @@ module('Integration | Component | magic-title', function(hooks) {
189
183
setupRenderingTest (hooks);
190
184
191
185
test (' should update title on button click' , async function (assert ) {
192
- assert .expect (2 );
193
-
194
186
await render (hbs` <MagicTitle />` );
195
187
196
188
assert .equal (this .element .querySelector (' h2' ).textContent .trim (), ' Hello World' , ' initial text is hello world' );
@@ -241,8 +233,9 @@ export default class CommentFormComponent extends Component {
241
233
```
242
234
243
235
Here's an example test that asserts that the specified ` externalAction ` function is invoked when the component's internal ` submitComment ` action is triggered by making use of a test double (dummy function).
244
- ` assert.expect(1) ` at the top of the test makes sure that the assertion inside the
245
- external action is called:
236
+ The value from the external action is captured in a shared variable (if and when it is called),
237
+ so that it can be explicitly asserted directly in the test function at the time where we
238
+ expect the closure to have been called.
246
239
247
240
``` javascript {data-filename="tests/integration/components/comment-form-test.js"}
248
241
import { module , test } from ' qunit' ;
@@ -254,12 +247,10 @@ module('Integration | Component | comment-form', function(hooks) {
254
247
setupRenderingTest (hooks);
255
248
256
249
test (' should trigger external action on form submit' , async function (assert ) {
257
- assert .expect (1 );
258
-
259
250
// test double for the external action
260
- this . set ( ' externalAction ' , ( actual ) => {
261
- let expected = { comment : ' You are not a wizard! ' };
262
- assert . deepEqual ( actual, expected, ' submitted value is passed to external action ' ) ;
251
+ let actual;
252
+ this . set ( ' externalAction ' , ( data ) => {
253
+ actual = data ;
263
254
});
264
255
265
256
await render (hbs` <CommentForm @submitComment={{this.externalAction}} />` );
@@ -269,6 +260,9 @@ module('Integration | Component | comment-form', function(hooks) {
269
260
270
261
// click the button to submit the form
271
262
await click (' .comment-input' );
263
+
264
+ let expected = { comment: ' You are not a wizard!' };
265
+ assert .deepEqual (actual, expected, ' submitted value is passed to external action' );
272
266
});
273
267
});
274
268
```
@@ -522,11 +516,11 @@ module('Integration | Component | delayed-typeahead', function(hooks) {
522
516
];
523
517
524
518
test (' should render results after typing a term' , async function (assert ) {
525
- assert .expect (2 );
526
-
527
519
this .set (' results' , []);
528
- this .set (' fetchResults' , (value ) => {
529
- assert .equal (value, ' test' , ' fetch closure action called with search value' );
520
+
521
+ let value;
522
+ this .set (' fetchResults' , (data ) => {
523
+ value = data;
530
524
this .set (' results' , stubResults);
531
525
});
532
526
@@ -535,6 +529,7 @@ module('Integration | Component | delayed-typeahead', function(hooks) {
535
529
this .element .querySelector (' input' ).dispatchEvent (new Event (' keyup' ));
536
530
537
531
await settled ();
532
+ assert .equal (value, ' test' , ' fetch closure action called with search value' );
538
533
539
534
assert .equal (this .element .querySelectorAll (' .result' ).length , 2 , ' two results rendered' );
540
535
});
0 commit comments