@@ -29,7 +29,7 @@ main() {
29
29
group ('connect' , () {
30
30
UiFactory <CounterProps > ConnectedCounter ;
31
31
TestJacket <CounterComponent > jacket;
32
- dynamic counterRef;
32
+ final counterRef = createRef < CounterComponent >() ;
33
33
34
34
JsConnectOptions connectOptions;
35
35
var originalConnect = mockableJsConnect;
@@ -83,10 +83,10 @@ main() {
83
83
84
84
render (
85
85
(ReduxProvider ()..store = store1)(
86
- (ConnectedCounter ()..ref= (ref){counterRef = ref;} )('test' ),
86
+ (ConnectedCounter ()..ref = counterRef )('test' ),
87
87
),
88
88
);
89
- expect (getDartComponent ( counterRef) , isA <CounterComponent >());
89
+ expect (counterRef.current , isA <CounterComponent >());
90
90
});
91
91
});
92
92
@@ -98,12 +98,12 @@ main() {
98
98
99
99
jacket = mount (
100
100
(ReduxProvider ()..store = store1)(
101
- (ConnectedCounter ()..ref = (ref){ counterRef = ref; } )('test' ),
101
+ (ConnectedCounter ()..ref = counterRef)('test' ),
102
102
),
103
103
);
104
104
105
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, 0 );
106
- expect (jacket.getNode () .innerHtml, contains ('Count: 0' ));
105
+ expect (counterRef.current .props.currentCount, 0 );
106
+ expect (jacket.mountNode .innerHtml, contains ('Count: 0' ));
107
107
});
108
108
109
109
test ('after dispatch' , () async {
@@ -113,21 +113,21 @@ main() {
113
113
114
114
jacket = mount (
115
115
(ReduxProvider ()..store = store1)(
116
- (ConnectedCounter ()..ref = (ref){ counterRef = ref; } )('test' ),
116
+ (ConnectedCounter ()..ref = counterRef)('test' ),
117
117
),
118
118
);
119
119
120
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, 0 );
121
- expect (jacket.getNode () .innerHtml, contains ('Count: 0' ));
120
+ expect (counterRef.current .props.currentCount, 0 );
121
+ expect (jacket.mountNode .innerHtml, contains ('Count: 0' ));
122
122
123
- var dispatchButton = getByTestId (jacket.getInstance () , 'button-increment' );
123
+ var dispatchButton = queryByTestId (jacket.mountNode , 'button-increment' );
124
124
click (dispatchButton);
125
125
126
126
// wait for the next tick for the async dispatch to propagate
127
127
await Future (() {});
128
128
129
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, 1 );
130
- expect (jacket.getNode () .innerHtml, contains ('Count: 1' ));
129
+ expect (counterRef.current .props.currentCount, 1 );
130
+ expect (jacket.mountNode .innerHtml, contains ('Count: 1' ));
131
131
});
132
132
});
133
133
@@ -139,12 +139,12 @@ main() {
139
139
140
140
jacket = mount (
141
141
(ReduxProvider ()..store = store1)(
142
- (ConnectedCounter ()..ref = (ref){ counterRef = ref; } )('test' ),
142
+ (ConnectedCounter ()..ref = counterRef)('test' ),
143
143
),
144
144
);
145
145
146
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, 0 );
147
- expect (jacket.getNode () .innerHtml, contains ('Count: 0' ));
146
+ expect (counterRef.current .props.currentCount, 0 );
147
+ expect (jacket.mountNode .innerHtml, contains ('Count: 0' ));
148
148
});
149
149
150
150
test ('after dispatch' , () async {
@@ -154,21 +154,21 @@ main() {
154
154
155
155
jacket = mount (
156
156
(ReduxProvider ()..store = store1)(
157
- (ConnectedCounter ()..ref = (ref){ counterRef = ref; } )('test' ),
157
+ (ConnectedCounter ()..ref = counterRef)('test' ),
158
158
),
159
159
);
160
160
161
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, 0 );
162
- expect (jacket.getNode () .innerHtml, contains ('Count: 0' ));
161
+ expect (counterRef.current .props.currentCount, 0 );
162
+ expect (jacket.mountNode .innerHtml, contains ('Count: 0' ));
163
163
164
- var dispatchButton = getByTestId (jacket.getInstance () , 'button-increment' );
164
+ var dispatchButton = queryByTestId (jacket.mountNode , 'button-increment' );
165
165
click (dispatchButton);
166
166
167
167
// wait for the next tick for the async dispatch to propagate
168
168
await Future (() {});
169
169
170
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, 1 );
171
- expect (jacket.getNode () .innerHtml, contains ('Count: 1' ));
170
+ expect (counterRef.current .props.currentCount, 1 );
171
+ expect (jacket.mountNode .innerHtml, contains ('Count: 1' ));
172
172
});
173
173
});
174
174
@@ -187,24 +187,24 @@ main() {
187
187
188
188
jacket = mount (
189
189
(ReduxProvider ()..store = store1)(
190
- (ConnectedCounter ()..ref = (ref){ counterRef = ref; } )('test' ),
190
+ (ConnectedCounter ()..ref = counterRef)('test' ),
191
191
),
192
192
);
193
193
194
- expect (getDartComponent < CounterComponent >( counterRef) .props.decrement, isA <Function >());
194
+ expect (counterRef.current .props.decrement, isA <Function >());
195
195
196
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, 0 );
197
- expect (jacket.getNode () .innerHtml, contains ('Count: 0' ));
196
+ expect (counterRef.current .props.currentCount, 0 );
197
+ expect (jacket.mountNode .innerHtml, contains ('Count: 0' ));
198
198
199
199
// Click button mapped to trigger `propFromDispatch` prop.
200
- var dispatchButton = getByTestId (jacket.getInstance () , 'button-decrement' );
200
+ var dispatchButton = queryByTestId (jacket.mountNode , 'button-decrement' );
201
201
click (dispatchButton);
202
202
203
203
// wait for the next tick for the async dispatch to propagate
204
204
await Future (() {});
205
205
206
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, - 1 );
207
- expect (jacket.getNode () .innerHtml, contains ('Count: -1' ));
206
+ expect (counterRef.current .props.currentCount, - 1 );
207
+ expect (jacket.mountNode .innerHtml, contains ('Count: -1' ));
208
208
});
209
209
});
210
210
@@ -223,24 +223,24 @@ main() {
223
223
224
224
jacket = mount (
225
225
(ReduxProvider ()..store = store1)(
226
- (ConnectedCounter ()..ref = (ref){ counterRef = ref; } )('test' ),
226
+ (ConnectedCounter ()..ref = counterRef)('test' ),
227
227
),
228
228
);
229
229
230
- expect (getDartComponent < CounterComponent >( counterRef) .props.decrement, isA <Function >());
230
+ expect (counterRef.current .props.decrement, isA <Function >());
231
231
232
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, 0 );
233
- expect (jacket.getNode () .innerHtml, contains ('Count: 0' ));
232
+ expect (counterRef.current .props.currentCount, 0 );
233
+ expect (jacket.mountNode .innerHtml, contains ('Count: 0' ));
234
234
235
235
// Click button mapped to trigger `propFromDispatch` prop.
236
- var dispatchButton = getByTestId (jacket.getInstance () , 'button-decrement' );
236
+ var dispatchButton = queryByTestId (jacket.mountNode , 'button-decrement' );
237
237
click (dispatchButton);
238
238
239
239
// wait for the next tick for the async dispatch to propagate
240
240
await Future (() {});
241
241
242
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, - 1 );
243
- expect (jacket.getNode () .innerHtml, contains ('Count: -1' ));
242
+ expect (counterRef.current .props.currentCount, - 1 );
243
+ expect (jacket.mountNode .innerHtml, contains ('Count: -1' ));
244
244
});
245
245
});
246
246
@@ -268,30 +268,30 @@ main() {
268
268
jacket = mount (
269
269
(ReduxProvider ()..store = store1)(
270
270
(ConnectedCounter ()
271
- ..ref = (ref){ counterRef = ref; }
271
+ ..ref = counterRef
272
272
// make `decrement` increment
273
273
..decrement = () {store1.dispatch (IncrementAction ());}
274
274
..currentCount = 900
275
275
)('test' ),
276
276
),
277
277
);
278
278
// `button-decrement` will be incrementing now
279
- var dispatchButton = getByTestId (jacket.getInstance () , 'button-decrement' );
279
+ var dispatchButton = queryByTestId (jacket.mountNode , 'button-decrement' );
280
280
281
- expect (getDartComponent < CounterComponent >( counterRef) .props.decrement, isA <Function >());
281
+ expect (counterRef.current .props.decrement, isA <Function >());
282
282
283
283
// state.count is at 0
284
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, 900 );
285
- expect (jacket.getNode () .innerHtml, contains ('Count: 900' ));
284
+ expect (counterRef.current .props.currentCount, 900 );
285
+ expect (jacket.mountNode .innerHtml, contains ('Count: 900' ));
286
286
287
287
// Click button mapped to trigger `propFromDispatch` prop.
288
288
click (dispatchButton); // state.count is now equal to 1
289
289
290
290
// wait for the next tick for the async dispatch to propagate
291
291
await Future (() {});
292
292
293
- expect (getDartComponent < CounterComponent >( counterRef) .props.currentCount, 1 );
294
- expect (jacket.getNode () .innerHtml, contains ('Count: 1' ));
293
+ expect (counterRef.current .props.currentCount, 1 );
294
+ expect (jacket.mountNode .innerHtml, contains ('Count: 1' ));
295
295
});
296
296
});
297
297
@@ -328,7 +328,6 @@ main() {
328
328
areStatePropsEqual: (next, prev) {
329
329
expect (next, isA <CounterProps >());
330
330
expect (prev, isA <CounterProps >());
331
- expect (next.currentCount, 1 );
332
331
methodsCalled.add ('areStatePropsEqual' );
333
332
// Force it to always be true, meaing it shouldnt re-render if they change.
334
333
return true ;
@@ -338,13 +337,13 @@ main() {
338
337
339
338
jacket = mount (
340
339
(ReduxProvider ()..store = store1)(
341
- (ConnectedCounter ()..ref = (ref){ counterRef = ref; } ..currentCount = 0 )('test' ),
340
+ (ConnectedCounter ()..ref = counterRef..currentCount = 0 )('test' ),
342
341
),
343
342
);
344
343
expect (methodsCalled, ['mapStateToProps' ]);
345
344
methodsCalled.clear ();
346
345
347
- var dispatchButton = getByTestId (jacket.getInstance () , 'button-increment' );
346
+ var dispatchButton = queryByTestId (jacket.mountNode , 'button-increment' );
348
347
click (dispatchButton);
349
348
350
349
// wait for the next tick for the async dispatch to propagate
@@ -353,7 +352,7 @@ main() {
353
352
// store.state.count should be 1 but does not re-render due to override in `areStatePropsEqual`
354
353
355
354
expect (methodsCalled, ['mapStateToProps' , 'areStatePropsEqual' ]);
356
- expect (jacket.getNode () .innerHtml, contains ('Count: 0' ));
355
+ expect (jacket.mountNode .innerHtml, contains ('Count: 0' ));
357
356
});
358
357
});
359
358
@@ -398,24 +397,24 @@ main() {
398
397
399
398
jacket = mount (
400
399
(ReduxProvider ()..store = store1)(
401
- (ConnectedCounter ()..ref = (ref){ counterRef = ref; } ..currentCount = 0 )('test' ),
400
+ (ConnectedCounter ()..ref = counterRef..currentCount = 0 )('test' ),
402
401
),
403
402
);
404
403
405
- // `mapStateToProps` is called once,
406
- // then `areStatesEqual` shows up 2 times due to `initialState`.
407
- expect (methodsCalled, ['mapStateToProps' , 'areStatesEqual' , 'areStatesEqual' ]);
404
+ expect (methodsCalled, contains ('mapStateToProps' ));
405
+ expect (methodsCalled, contains ('areStatesEqual' ));
408
406
methodsCalled.clear ();
409
407
410
- var dispatchButton = getByTestId (jacket.getInstance () , 'button-increment' );
408
+ var dispatchButton = queryByTestId (jacket.mountNode , 'button-increment' );
411
409
click (dispatchButton);
412
410
413
411
// wait for the next tick for the async dispatch to propagate
414
412
await Future (() {});
415
413
416
- // only checks `areStatesEqual` and does not call `mapStateToProps` since it returned `true`.
417
- expect (methodsCalled, ['areStatesEqual' ]);
418
- expect (jacket.getNode ().innerHtml, contains ('Count: 0' ));
414
+ // only calls `areStatesEqual` and does not call `mapStateToProps` since it returned `true`.
415
+ expect (methodsCalled, isNot (contains ('mapStateToProps' )));
416
+ expect (methodsCalled, contains ('areStatesEqual' ));
417
+ expect (jacket.mountNode.innerHtml, contains ('Count: 0' ));
419
418
});
420
419
});
421
420
});
@@ -449,13 +448,13 @@ main() {
449
448
),
450
449
));
451
450
452
- var bigCounter = getDartComponent ( getByTestId ( jacket.getInstance () , 'big-counter' ) );
453
- var dispatchButton = queryByTestId (findDomNode ( bigCounter) , 'button-increment' );
451
+ var bigCounter = queryByTestId ( jacket.mountNode , 'big-counter' );
452
+ var dispatchButton = queryByTestId (bigCounter, 'button-increment' );
454
453
click (dispatchButton);
455
454
456
455
await Future ((){});
457
456
458
- expect (findDomNode ( bigCounter) .innerHtml, contains ('Count: 100' ));
457
+ expect (bigCounter.innerHtml, contains ('Count: 100' ));
459
458
});
460
459
461
460
test ('correctly renderes when contexts are nested' , () async {
@@ -492,11 +491,11 @@ main() {
492
491
)
493
492
);
494
493
495
- var bigCounter = getDartComponent ( getByTestId ( jacket.getInstance () , 'big-counter' ) );
496
- var smallCounter = getDartComponent ( getByTestId ( jacket.getInstance () , 'small-counter' ) );
494
+ var bigCounter = queryByTestId ( jacket.mountNode , 'big-counter' );
495
+ var smallCounter = queryByTestId ( jacket.mountNode , 'small-counter' );
497
496
498
- var smallDispatchButton = queryByTestId (findDomNode ( smallCounter) , 'button-increment' );
499
- var dispatchButton = queryByTestId (findDomNode ( bigCounter) , 'button-increment' );
497
+ var smallDispatchButton = queryByTestId (smallCounter, 'button-increment' );
498
+ var dispatchButton = queryByTestId (bigCounter, 'button-increment' );
500
499
501
500
click (dispatchButton);
502
501
click (smallDispatchButton);
@@ -507,7 +506,7 @@ main() {
507
506
expect (findDomNode (bigCounter).innerHtml, contains ('Count: 100' ), reason: 'Should have a count of 100' );
508
507
509
508
// Normal counter incremented only 1 at both instances
510
- expect (findDomNode (getByTestId (jacket.getInstance () , 'outside' )).innerHtml, contains ('Count: 1</div>' ));
509
+ expect (findDomNode (queryByTestId (jacket.mountNode , 'outside' )).innerHtml, contains ('Count: 1</div>' ));
511
510
expect (findDomNode (bigCounter).innerHtml, contains ('Count: 1</div>' ));
512
511
});
513
512
});
0 commit comments