@@ -6,11 +6,19 @@ import { click, render, settled } from '@ember/test-helpers';
66import { module , test } from ' qunit' ;
77import { setupRenderingTest } from ' ember-qunit' ;
88
9+ import { modifier } from ' ember-modifier' ;
910import { resource , resourceFactory , use } from ' ember-resources' ;
1011import { trackedFunction } from ' reactiveweb/function' ;
1112
1213const timeout = (ms : number ) => new Promise ((resolve ) => setTimeout (resolve , ms ));
1314
15+ const logText = modifier (function (_element , [value ]) {
16+ // eslint-disable-next-line no-console
17+ console .log (value );
18+
19+ return () => {};
20+ });
21+
1422module (' Utils | trackedFunction | rendering' , function (hooks ) {
1523 setupRenderingTest (hooks );
1624
@@ -237,28 +245,26 @@ module('Utils | trackedFunction | rendering', function (hooks) {
237245
238246 test (' failing case' , async function (assert ) {
239247 class TestCase {
240- items = trackedFunction (this , async () => {
241- const items = await Promise .resolve ([3 , 4 , 5 ]);
242-
243- return items ;
248+ lengthPromise = trackedFunction (this , async () => {
249+ return await Promise .resolve (3 );
244250 });
245251
246- get firstItem () {
247- return this .items .value ?.[ 0 ] ;
252+ get length () {
253+ return this .lengthPromise .value ;
248254 }
249255
250256 stringArray = trackedFunction (this , async () => {
251- if (! this .firstItem ) return [];
257+ if (! this .length ) return [];
252258
253259 const stringArray = await Promise .resolve (
254- Array .from ({ length: this .firstItem }, () => ' item' )
255- );
260+ Array .from ({ length: this .length }, () => ' item' )
261+ ); // ['item', 'item', 'item']
256262
257263 return stringArray ;
258264 });
259265
260266 get endResult() {
261- return this .stringArray .value ?. join ( ' , ' ) ?? []. join ( ' ' ) ;
267+ return this .stringArray .value ;
262268 }
263269 }
264270
@@ -268,7 +274,8 @@ module('Utils | trackedFunction | rendering', function (hooks) {
268274 setTestCase = () => (this .testCase = new TestCase ());
269275
270276 <template >
271- <out >{{this .testCase.endResult }} </out >
277+ <div {{logText this . testCase.endResult}} />
278+ <out >{{JSON.stringify this . testCase.endResult }} </out >
272279 <button type =" button" {{on " click" this . setTestCase}} ></button >
273280 </template >
274281 }
@@ -279,6 +286,6 @@ module('Utils | trackedFunction | rendering', function (hooks) {
279286
280287 await click (' button' );
281288
282- assert .dom (' out' ).hasText (' item, item, item' );
289+ assert .dom (' out' ).hasText (JSON . stringify ([ ' item' , ' item' , ' item' ]))
283290 });
284291});
0 commit comments