File tree 2 files changed +23
-13
lines changed
testing/ember-app/tests/utils/cell
2 files changed +23
-13
lines changed Original file line number Diff line number Diff line change 1
1
import { tracked } from '@glimmer/tracking' ;
2
2
import { assert } from '@ember/debug' ;
3
3
4
- class Cell < T > {
5
- @tracked current : T | undefined ;
4
+ class Cell < Value = unknown > {
5
+ @tracked declare current : Value ;
6
6
7
7
constructor ( ) ;
8
- constructor ( initialValue : T ) ;
9
- constructor ( initialValue ?: T ) {
10
- this . current = initialValue ;
8
+ constructor ( initialValue : Value ) ;
9
+ constructor ( initialValue ?: Value ) {
10
+ if ( initialValue !== undefined ) {
11
+ this . current = initialValue ;
12
+ }
11
13
}
12
14
13
15
toggle = ( ) => {
@@ -54,8 +56,8 @@ class Cell<T> {
54
56
* </template>
55
57
* ```
56
58
*/
57
- export function cell < T > ( initialValue ?: T ) : Cell < T > {
58
- if ( initialValue ) {
59
+ export function cell < Value = unknown > ( initialValue ?: Value ) : Cell < Value > {
60
+ if ( initialValue !== undefined ) {
59
61
return new Cell ( initialValue ) ;
60
62
}
61
63
Original file line number Diff line number Diff line change 1
1
import { render , settled } from ' @ember/test-helpers' ;
2
- import { hbs } from 'ember-cli-htmlbars' ;
3
2
import { module , test } from ' qunit' ;
4
3
import { setupRenderingTest } from ' ember-qunit' ;
5
4
@@ -9,18 +8,27 @@ module('Utils | cell | rendering', function (hooks) {
9
8
setupRenderingTest (hooks );
10
9
11
10
test (' it works' , async function (assert ) {
12
- let state = cell ( ) ;
11
+ let state = cell < string | undefined > ();
13
12
14
- this . setProperties ( { state } ) ;
15
-
16
- await render ( hbs `{{this.state.current}}` ) ;
13
+ await render (<template >{{state.current }} </template >);
17
14
18
15
assert .dom ().doesNotContainText (' hello' );
19
16
20
17
state .current = ' hello' ;
18
+ await settled ();
19
+ assert .dom ().hasText (' hello' );
20
+ });
21
21
22
+ test (' it works with an initial value' , async function (assert ) {
23
+ let state = cell (0 );
24
+
25
+ await render (<template >{{state.current }} </template >);
26
+
27
+ assert .dom ().hasText (' 0' );
28
+
29
+ state .current ++ ;
22
30
await settled ();
23
31
24
- assert . dom ( ) . hasText ( 'hello ' ) ;
32
+ assert .dom ().hasText (' 1 ' );
25
33
});
26
34
});
You can’t perform that action at this time.
0 commit comments