@@ -71,8 +71,6 @@ module('Integration | Component | pretty-color', function(hooks) {
7171 setupRenderingTest (hooks);
7272
7373 test (' should change colors' , async function (assert ) {
74- assert .expect (1 );
75-
7674 // set the outer context to red
7775 this .set (' colorValue' , ' red' );
7876
@@ -102,8 +100,6 @@ module('Integration | Component | pretty-color', function(hooks) {
102100 setupRenderingTest (hooks);
103101
104102 test (' it renders' , async function (assert ) {
105- assert .expect (2 );
106-
107103 // set the outer context to red
108104 this .set (' colorValue' , ' red' );
109105
@@ -129,8 +125,6 @@ module('Integration | Component | pretty-color', function(hooks) {
129125 setupRenderingTest (hooks);
130126
131127 test (' it renders' , async function (assert ) {
132- assert .expect (2 );
133-
134128 this .set (' colorValue' , ' orange' );
135129
136130 await render (hbs` <PrettyColor @name={{this.colorValue}} />` );
@@ -189,8 +183,6 @@ module('Integration | Component | magic-title', function(hooks) {
189183 setupRenderingTest (hooks);
190184
191185 test (' should update title on button click' , async function (assert ) {
192- assert .expect (2 );
193-
194186 await render (hbs` <MagicTitle />` );
195187
196188 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 {
241233```
242234
243235Here'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 action to have been called.
246239
247240``` javascript {data-filename="tests/integration/components/comment-form-test.js"}
248241import { module , test } from ' qunit' ;
@@ -254,12 +247,10 @@ module('Integration | Component | comment-form', function(hooks) {
254247 setupRenderingTest (hooks);
255248
256249 test (' should trigger external action on form submit' , async function (assert ) {
257- assert .expect (1 );
258-
259250 // 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 ;
263254 });
264255
265256 await render (hbs` <CommentForm @submitComment={{this.externalAction}} />` );
@@ -269,6 +260,9 @@ module('Integration | Component | comment-form', function(hooks) {
269260
270261 // click the button to submit the form
271262 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' );
272266 });
273267});
274268```
@@ -522,11 +516,11 @@ module('Integration | Component | delayed-typeahead', function(hooks) {
522516 ];
523517
524518 test (' should render results after typing a term' , async function (assert ) {
525- assert .expect (2 );
526-
527519 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;
530524 this .set (' results' , stubResults);
531525 });
532526
@@ -535,6 +529,7 @@ module('Integration | Component | delayed-typeahead', function(hooks) {
535529 this .element .querySelector (' input' ).dispatchEvent (new Event (' keyup' ));
536530
537531 await settled ();
532+ assert .equal (value, ' test' , ' fetch closure action called with search value' );
538533
539534 assert .equal (this .element .querySelectorAll (' .result' ).length , 2 , ' two results rendered' );
540535 });
0 commit comments