@wordpress/data 7.3.0 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/package.json +8 -8
- package/src/components/use-dispatch/test/use-dispatch.js +84 -127
- package/src/components/use-select/test/index.js +93 -101
- package/src/components/use-select/test/suspense.js +6 -6
- package/src/components/with-dispatch/test/index.js +116 -178
- package/src/components/with-select/test/index.js +224 -309
- package/src/redux-store/test/index.js +3 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { act, render, fireEvent } from '@testing-library/react';
|
|
4
|
+
import { act, render, fireEvent, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -44,7 +44,7 @@ describe( 'useSelect', () => {
|
|
|
44
44
|
return <div role="status">{ data.results }</div>;
|
|
45
45
|
} );
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
render(
|
|
48
48
|
<RegistryProvider value={ registry }>
|
|
49
49
|
<TestComponent keyName="foo" />
|
|
50
50
|
</RegistryProvider>
|
|
@@ -57,7 +57,7 @@ describe( 'useSelect', () => {
|
|
|
57
57
|
expect( TestComponent ).toHaveBeenCalledTimes( 1 );
|
|
58
58
|
|
|
59
59
|
// Ensure expected state was rendered.
|
|
60
|
-
expect(
|
|
60
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'bar' );
|
|
61
61
|
} );
|
|
62
62
|
|
|
63
63
|
it( 'uses memoized selector if dependencies do not change', () => {
|
|
@@ -76,7 +76,7 @@ describe( 'useSelect', () => {
|
|
|
76
76
|
return <div role="status">{ data }</div>;
|
|
77
77
|
} );
|
|
78
78
|
|
|
79
|
-
const
|
|
79
|
+
const { rerender } = render(
|
|
80
80
|
<RegistryProvider value={ registry }>
|
|
81
81
|
<TestComponent keyName="foo" change={ true } />
|
|
82
82
|
</RegistryProvider>
|
|
@@ -87,10 +87,10 @@ describe( 'useSelect', () => {
|
|
|
87
87
|
expect( TestComponent ).toHaveBeenCalledTimes( 1 );
|
|
88
88
|
|
|
89
89
|
// Ensure expected state was rendered.
|
|
90
|
-
expect(
|
|
90
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'foo' );
|
|
91
91
|
|
|
92
92
|
// Rerender with non dependency changed.
|
|
93
|
-
|
|
93
|
+
rerender(
|
|
94
94
|
<RegistryProvider value={ registry }>
|
|
95
95
|
<TestComponent keyName="foo" change={ false } />
|
|
96
96
|
</RegistryProvider>
|
|
@@ -101,10 +101,10 @@ describe( 'useSelect', () => {
|
|
|
101
101
|
expect( TestComponent ).toHaveBeenCalledTimes( 2 );
|
|
102
102
|
|
|
103
103
|
// Ensure expected state was rendered.
|
|
104
|
-
expect(
|
|
104
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'foo' );
|
|
105
105
|
|
|
106
106
|
// Rerender with dependency changed.
|
|
107
|
-
|
|
107
|
+
rerender(
|
|
108
108
|
<RegistryProvider value={ registry }>
|
|
109
109
|
<TestComponent keyName="bar" change={ false } />
|
|
110
110
|
</RegistryProvider>
|
|
@@ -115,7 +115,7 @@ describe( 'useSelect', () => {
|
|
|
115
115
|
expect( TestComponent ).toHaveBeenCalledTimes( 3 );
|
|
116
116
|
|
|
117
117
|
// Ensure expected state was rendered.
|
|
118
|
-
expect(
|
|
118
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'bar' );
|
|
119
119
|
} );
|
|
120
120
|
|
|
121
121
|
it( 'avoid calling nested listener after unmounted', async () => {
|
|
@@ -144,14 +144,14 @@ describe( 'useSelect', () => {
|
|
|
144
144
|
return show ? <Child /> : 'none';
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
render(
|
|
148
148
|
<RegistryProvider value={ registry }>
|
|
149
149
|
<Parent />
|
|
150
150
|
</RegistryProvider>
|
|
151
151
|
);
|
|
152
152
|
|
|
153
153
|
// Initial render renders only parent and subscribes the parent to store.
|
|
154
|
-
expect(
|
|
154
|
+
expect( screen.getByText( 'none' ) ).toBeInTheDocument();
|
|
155
155
|
expect( mapSelectParent ).toHaveBeenCalledTimes( 2 );
|
|
156
156
|
expect( mapSelectChild ).toHaveBeenCalledTimes( 0 );
|
|
157
157
|
|
|
@@ -166,7 +166,7 @@ describe( 'useSelect', () => {
|
|
|
166
166
|
} );
|
|
167
167
|
|
|
168
168
|
// Child was rendered and subscribed to the store, as the _second_ subscription.
|
|
169
|
-
expect(
|
|
169
|
+
expect( screen.getByText( 'yes' ) ).toBeInTheDocument();
|
|
170
170
|
expect( mapSelectParent ).toHaveBeenCalledTimes( 3 );
|
|
171
171
|
expect( mapSelectChild ).toHaveBeenCalledTimes( 2 );
|
|
172
172
|
|
|
@@ -178,7 +178,7 @@ describe( 'useSelect', () => {
|
|
|
178
178
|
// Check that child was unmounted without any extra state update being performed on it.
|
|
179
179
|
// I.e., `mapSelectChild` was never called again, and no "state update on an unmounted
|
|
180
180
|
// component" warning was triggered.
|
|
181
|
-
expect(
|
|
181
|
+
expect( screen.getByText( 'none' ) ).toBeInTheDocument();
|
|
182
182
|
expect( mapSelectParent ).toHaveBeenCalledTimes( 4 );
|
|
183
183
|
expect( mapSelectChild ).toHaveBeenCalledTimes( 2 );
|
|
184
184
|
} );
|
|
@@ -232,13 +232,13 @@ describe( 'useSelect', () => {
|
|
|
232
232
|
( type, testValues ) => {
|
|
233
233
|
const [ valueA, valueB ] = testValues;
|
|
234
234
|
selectorSpy.mockReturnValue( valueA );
|
|
235
|
-
|
|
235
|
+
render(
|
|
236
236
|
<RegistryProvider value={ registry }>
|
|
237
237
|
<TestComponent />
|
|
238
238
|
</RegistryProvider>
|
|
239
239
|
);
|
|
240
240
|
// Ensure expected state was rendered.
|
|
241
|
-
expect(
|
|
241
|
+
expect( screen.getByRole( 'status' ).dataset.d ).toBe(
|
|
242
242
|
JSON.stringify( valueA )
|
|
243
243
|
);
|
|
244
244
|
|
|
@@ -248,7 +248,7 @@ describe( 'useSelect', () => {
|
|
|
248
248
|
selectorSpy.mockReturnValue( valueB );
|
|
249
249
|
registry.dispatch( 'testStore' ).forceUpdate();
|
|
250
250
|
} );
|
|
251
|
-
expect(
|
|
251
|
+
expect( screen.getByRole( 'status' ).dataset.d ).toBe(
|
|
252
252
|
JSON.stringify( valueB )
|
|
253
253
|
);
|
|
254
254
|
expect( mapSelectSpy ).toHaveBeenCalledTimes( 3 );
|
|
@@ -297,7 +297,7 @@ describe( 'useSelect', () => {
|
|
|
297
297
|
return <div role="status">{ count1 }</div>;
|
|
298
298
|
} );
|
|
299
299
|
|
|
300
|
-
const
|
|
300
|
+
const { unmount } = render(
|
|
301
301
|
<RegistryProvider value={ registry }>
|
|
302
302
|
<TestComponent />
|
|
303
303
|
</RegistryProvider>
|
|
@@ -306,7 +306,7 @@ describe( 'useSelect', () => {
|
|
|
306
306
|
expect( selectCount1 ).toHaveBeenCalledTimes( 2 );
|
|
307
307
|
expect( selectCount2 ).toHaveBeenCalledTimes( 2 );
|
|
308
308
|
expect( TestComponent ).toHaveBeenCalledTimes( 1 );
|
|
309
|
-
expect(
|
|
309
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0' );
|
|
310
310
|
|
|
311
311
|
act( () => {
|
|
312
312
|
registry.dispatch( 'store-2' ).increment();
|
|
@@ -315,7 +315,7 @@ describe( 'useSelect', () => {
|
|
|
315
315
|
expect( selectCount1 ).toHaveBeenCalledTimes( 2 );
|
|
316
316
|
expect( selectCount2 ).toHaveBeenCalledTimes( 3 );
|
|
317
317
|
expect( TestComponent ).toHaveBeenCalledTimes( 2 );
|
|
318
|
-
expect(
|
|
318
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0' );
|
|
319
319
|
|
|
320
320
|
act( () => {
|
|
321
321
|
registry.dispatch( 'store-1' ).increment();
|
|
@@ -324,10 +324,10 @@ describe( 'useSelect', () => {
|
|
|
324
324
|
expect( selectCount1 ).toHaveBeenCalledTimes( 3 );
|
|
325
325
|
expect( selectCount2 ).toHaveBeenCalledTimes( 3 );
|
|
326
326
|
expect( TestComponent ).toHaveBeenCalledTimes( 3 );
|
|
327
|
-
expect(
|
|
327
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '1' );
|
|
328
328
|
|
|
329
329
|
// Test if the unsubscribers get called correctly.
|
|
330
|
-
|
|
330
|
+
expect( () => unmount() ).not.toThrow();
|
|
331
331
|
} );
|
|
332
332
|
|
|
333
333
|
it( 'can subscribe to multiple stores at once', () => {
|
|
@@ -354,28 +354,28 @@ describe( 'useSelect', () => {
|
|
|
354
354
|
);
|
|
355
355
|
} );
|
|
356
356
|
|
|
357
|
-
|
|
357
|
+
render(
|
|
358
358
|
<RegistryProvider value={ registry }>
|
|
359
359
|
<TestComponent />
|
|
360
360
|
</RegistryProvider>
|
|
361
361
|
);
|
|
362
362
|
|
|
363
363
|
expect( selectCount1And2 ).toHaveBeenCalledTimes( 2 );
|
|
364
|
-
expect(
|
|
364
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0,0' );
|
|
365
365
|
|
|
366
366
|
act( () => {
|
|
367
367
|
registry.dispatch( 'store-2' ).increment();
|
|
368
368
|
} );
|
|
369
369
|
|
|
370
370
|
expect( selectCount1And2 ).toHaveBeenCalledTimes( 3 );
|
|
371
|
-
expect(
|
|
371
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0,1' );
|
|
372
372
|
|
|
373
373
|
act( () => {
|
|
374
374
|
registry.dispatch( 'store-3' ).increment();
|
|
375
375
|
} );
|
|
376
376
|
|
|
377
377
|
expect( selectCount1And2 ).toHaveBeenCalledTimes( 3 );
|
|
378
|
-
expect(
|
|
378
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0,1' );
|
|
379
379
|
} );
|
|
380
380
|
|
|
381
381
|
it( 're-calls the selector when deps changed', () => {
|
|
@@ -404,14 +404,14 @@ describe( 'useSelect', () => {
|
|
|
404
404
|
);
|
|
405
405
|
} );
|
|
406
406
|
|
|
407
|
-
|
|
407
|
+
render(
|
|
408
408
|
<RegistryProvider value={ registry }>
|
|
409
409
|
<TestComponent />
|
|
410
410
|
</RegistryProvider>
|
|
411
411
|
);
|
|
412
412
|
|
|
413
413
|
expect( selectCount1AndDep ).toHaveBeenCalledTimes( 2 );
|
|
414
|
-
expect(
|
|
414
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
415
415
|
'count:0,dep:0'
|
|
416
416
|
);
|
|
417
417
|
|
|
@@ -420,7 +420,7 @@ describe( 'useSelect', () => {
|
|
|
420
420
|
} );
|
|
421
421
|
|
|
422
422
|
expect( selectCount1AndDep ).toHaveBeenCalledTimes( 4 );
|
|
423
|
-
expect(
|
|
423
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
424
424
|
'count:0,dep:1'
|
|
425
425
|
);
|
|
426
426
|
|
|
@@ -429,7 +429,7 @@ describe( 'useSelect', () => {
|
|
|
429
429
|
} );
|
|
430
430
|
|
|
431
431
|
expect( selectCount1AndDep ).toHaveBeenCalledTimes( 5 );
|
|
432
|
-
expect(
|
|
432
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
433
433
|
'count:1,dep:1'
|
|
434
434
|
);
|
|
435
435
|
} );
|
|
@@ -477,16 +477,16 @@ describe( 'useSelect', () => {
|
|
|
477
477
|
);
|
|
478
478
|
};
|
|
479
479
|
|
|
480
|
-
|
|
480
|
+
render(
|
|
481
481
|
<RegistryProvider value={ registry }>
|
|
482
482
|
<TestComponent />
|
|
483
483
|
</RegistryProvider>
|
|
484
484
|
);
|
|
485
485
|
|
|
486
|
-
fireEvent.click(
|
|
486
|
+
fireEvent.click( screen.getByText( 'triggerChildDispatch' ) );
|
|
487
487
|
|
|
488
488
|
expect( selectCount1AndDep ).toHaveBeenCalledTimes( 3 );
|
|
489
|
-
expect(
|
|
489
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
490
490
|
'count1:1'
|
|
491
491
|
);
|
|
492
492
|
} );
|
|
@@ -525,14 +525,14 @@ describe( 'useSelect', () => {
|
|
|
525
525
|
);
|
|
526
526
|
} );
|
|
527
527
|
|
|
528
|
-
|
|
528
|
+
render(
|
|
529
529
|
<RegistryProvider value={ registry }>
|
|
530
530
|
<TestComponent />
|
|
531
531
|
</RegistryProvider>
|
|
532
532
|
);
|
|
533
533
|
|
|
534
534
|
expect( selectCount1And2 ).toHaveBeenCalledTimes( 2 );
|
|
535
|
-
expect(
|
|
535
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
536
536
|
'count1:0,count2:0'
|
|
537
537
|
);
|
|
538
538
|
|
|
@@ -541,7 +541,7 @@ describe( 'useSelect', () => {
|
|
|
541
541
|
} );
|
|
542
542
|
|
|
543
543
|
expect( selectCount1And2 ).toHaveBeenCalledTimes( 3 );
|
|
544
|
-
expect(
|
|
544
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
545
545
|
'count1:0,count2:1'
|
|
546
546
|
);
|
|
547
547
|
} );
|
|
@@ -581,7 +581,7 @@ describe( 'useSelect', () => {
|
|
|
581
581
|
);
|
|
582
582
|
} );
|
|
583
583
|
|
|
584
|
-
|
|
584
|
+
render(
|
|
585
585
|
<RegistryProvider value={ registry }>
|
|
586
586
|
<TestComponent />
|
|
587
587
|
</RegistryProvider>
|
|
@@ -589,15 +589,15 @@ describe( 'useSelect', () => {
|
|
|
589
589
|
|
|
590
590
|
expect( selectCount1 ).toHaveBeenCalledTimes( 0 );
|
|
591
591
|
expect( selectCount2 ).toHaveBeenCalledTimes( 2 );
|
|
592
|
-
expect(
|
|
592
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
593
593
|
'count2'
|
|
594
594
|
);
|
|
595
595
|
|
|
596
|
-
|
|
596
|
+
screen.getByText( 'Toggle' ).click();
|
|
597
597
|
|
|
598
598
|
expect( selectCount1 ).toHaveBeenCalledTimes( 2 );
|
|
599
599
|
expect( selectCount2 ).toHaveBeenCalledTimes( 2 );
|
|
600
|
-
expect(
|
|
600
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
601
601
|
'count1'
|
|
602
602
|
);
|
|
603
603
|
} );
|
|
@@ -624,7 +624,7 @@ describe( 'useSelect', () => {
|
|
|
624
624
|
);
|
|
625
625
|
} );
|
|
626
626
|
|
|
627
|
-
|
|
627
|
+
render(
|
|
628
628
|
<RegistryProvider value={ registry }>
|
|
629
629
|
<RegistryProvider value={ subRegistry }>
|
|
630
630
|
<TestComponent />
|
|
@@ -632,7 +632,7 @@ describe( 'useSelect', () => {
|
|
|
632
632
|
</RegistryProvider>
|
|
633
633
|
);
|
|
634
634
|
|
|
635
|
-
expect(
|
|
635
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
636
636
|
'parent:0,child:0'
|
|
637
637
|
);
|
|
638
638
|
|
|
@@ -640,7 +640,7 @@ describe( 'useSelect', () => {
|
|
|
640
640
|
registry.dispatch( 'parent-store' ).increment();
|
|
641
641
|
} );
|
|
642
642
|
|
|
643
|
-
expect(
|
|
643
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
644
644
|
'parent:1,child:0'
|
|
645
645
|
);
|
|
646
646
|
} );
|
|
@@ -664,13 +664,13 @@ describe( 'useSelect', () => {
|
|
|
664
664
|
);
|
|
665
665
|
} );
|
|
666
666
|
|
|
667
|
-
const
|
|
667
|
+
const { unmount } = render(
|
|
668
668
|
<RegistryProvider value={ registry }>
|
|
669
669
|
<TestComponent />
|
|
670
670
|
</RegistryProvider>
|
|
671
671
|
);
|
|
672
672
|
|
|
673
|
-
expect(
|
|
673
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
674
674
|
'count1:0,count2:blank'
|
|
675
675
|
);
|
|
676
676
|
|
|
@@ -678,12 +678,12 @@ describe( 'useSelect', () => {
|
|
|
678
678
|
registry.dispatch( 'store-1' ).increment();
|
|
679
679
|
} );
|
|
680
680
|
|
|
681
|
-
expect(
|
|
681
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent(
|
|
682
682
|
'count1:1,count2:blank'
|
|
683
683
|
);
|
|
684
684
|
|
|
685
685
|
// Test if the unsubscribers get called correctly.
|
|
686
|
-
|
|
686
|
+
expect( () => unmount() ).not.toThrow();
|
|
687
687
|
} );
|
|
688
688
|
|
|
689
689
|
it( 'handles registration of a non-existing store during rendering', () => {
|
|
@@ -698,15 +698,13 @@ describe( 'useSelect', () => {
|
|
|
698
698
|
return <div role="status">{ state }</div>;
|
|
699
699
|
} );
|
|
700
700
|
|
|
701
|
-
const
|
|
701
|
+
const { unmount } = render(
|
|
702
702
|
<RegistryProvider value={ registry }>
|
|
703
703
|
<TestComponent />
|
|
704
704
|
</RegistryProvider>
|
|
705
705
|
);
|
|
706
706
|
|
|
707
|
-
expect(
|
|
708
|
-
'blank'
|
|
709
|
-
);
|
|
707
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'blank' );
|
|
710
708
|
|
|
711
709
|
act( () => {
|
|
712
710
|
registry.registerStore(
|
|
@@ -716,18 +714,16 @@ describe( 'useSelect', () => {
|
|
|
716
714
|
} );
|
|
717
715
|
|
|
718
716
|
// This is not ideal, but is the way it's working before and we want to prevent breaking changes.
|
|
719
|
-
expect(
|
|
720
|
-
'blank'
|
|
721
|
-
);
|
|
717
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'blank' );
|
|
722
718
|
|
|
723
719
|
act( () => {
|
|
724
720
|
registry.dispatch( 'not-yet-registered-store' ).increment();
|
|
725
721
|
} );
|
|
726
722
|
|
|
727
|
-
expect(
|
|
723
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '1' );
|
|
728
724
|
|
|
729
725
|
// Test if the unsubscribers get called correctly.
|
|
730
|
-
|
|
726
|
+
expect( () => unmount() ).not.toThrow();
|
|
731
727
|
} );
|
|
732
728
|
|
|
733
729
|
it( 'handles registration of a non-existing store of sub-registry during rendering', () => {
|
|
@@ -745,7 +741,7 @@ describe( 'useSelect', () => {
|
|
|
745
741
|
return <div role="status">{ state }</div>;
|
|
746
742
|
} );
|
|
747
743
|
|
|
748
|
-
const
|
|
744
|
+
const { unmount } = render(
|
|
749
745
|
<RegistryProvider value={ registry }>
|
|
750
746
|
<RegistryProvider value={ subRegistry }>
|
|
751
747
|
<TestComponent />
|
|
@@ -753,9 +749,7 @@ describe( 'useSelect', () => {
|
|
|
753
749
|
</RegistryProvider>
|
|
754
750
|
);
|
|
755
751
|
|
|
756
|
-
expect(
|
|
757
|
-
'blank'
|
|
758
|
-
);
|
|
752
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'blank' );
|
|
759
753
|
|
|
760
754
|
act( () => {
|
|
761
755
|
registry.registerStore(
|
|
@@ -765,9 +759,7 @@ describe( 'useSelect', () => {
|
|
|
765
759
|
} );
|
|
766
760
|
|
|
767
761
|
// This is not ideal, but is the way it's working before and we want to prevent breaking changes.
|
|
768
|
-
expect(
|
|
769
|
-
'blank'
|
|
770
|
-
);
|
|
762
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'blank' );
|
|
771
763
|
|
|
772
764
|
act( () => {
|
|
773
765
|
registry
|
|
@@ -775,10 +767,10 @@ describe( 'useSelect', () => {
|
|
|
775
767
|
.increment();
|
|
776
768
|
} );
|
|
777
769
|
|
|
778
|
-
expect(
|
|
770
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '1' );
|
|
779
771
|
|
|
780
772
|
// Test if the unsubscribers get called correctly.
|
|
781
|
-
|
|
773
|
+
expect( () => unmount() ).not.toThrow();
|
|
782
774
|
} );
|
|
783
775
|
|
|
784
776
|
it( 'handles custom generic stores without a unsubscribe function', () => {
|
|
@@ -824,21 +816,21 @@ describe( 'useSelect', () => {
|
|
|
824
816
|
return <div role="status">{ state }</div>;
|
|
825
817
|
} );
|
|
826
818
|
|
|
827
|
-
const
|
|
819
|
+
const { unmount } = render(
|
|
828
820
|
<RegistryProvider value={ registry }>
|
|
829
821
|
<TestComponent />
|
|
830
822
|
</RegistryProvider>
|
|
831
823
|
);
|
|
832
824
|
|
|
833
|
-
expect(
|
|
825
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0' );
|
|
834
826
|
|
|
835
827
|
act( () => {
|
|
836
828
|
registry.dispatch( customStore ).increment();
|
|
837
829
|
} );
|
|
838
830
|
|
|
839
|
-
expect(
|
|
831
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '1' );
|
|
840
832
|
|
|
841
|
-
expect( () =>
|
|
833
|
+
expect( () => unmount() ).not.toThrow();
|
|
842
834
|
} );
|
|
843
835
|
} );
|
|
844
836
|
|
|
@@ -874,7 +866,7 @@ describe( 'useSelect', () => {
|
|
|
874
866
|
return <div role="status">{ count }</div>;
|
|
875
867
|
} );
|
|
876
868
|
|
|
877
|
-
|
|
869
|
+
render(
|
|
878
870
|
<AsyncModeProvider value={ true }>
|
|
879
871
|
<RegistryProvider value={ registry }>
|
|
880
872
|
<TestComponent />
|
|
@@ -887,7 +879,7 @@ describe( 'useSelect', () => {
|
|
|
887
879
|
expect( TestComponent ).toHaveBeenCalledTimes( 1 );
|
|
888
880
|
|
|
889
881
|
// Ensure expected state was rendered.
|
|
890
|
-
expect(
|
|
882
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0' );
|
|
891
883
|
|
|
892
884
|
act( () => {
|
|
893
885
|
registry.dispatch( 'counter' ).inc();
|
|
@@ -895,9 +887,9 @@ describe( 'useSelect', () => {
|
|
|
895
887
|
|
|
896
888
|
// still not called right after increment
|
|
897
889
|
expect( selectSpy ).toHaveBeenCalledTimes( 2 );
|
|
898
|
-
expect(
|
|
890
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0' );
|
|
899
891
|
|
|
900
|
-
expect( await
|
|
892
|
+
expect( await screen.findByText( 1 ) ).toBeInTheDocument();
|
|
901
893
|
|
|
902
894
|
expect( selectSpy ).toHaveBeenCalledTimes( 3 );
|
|
903
895
|
expect( TestComponent ).toHaveBeenCalledTimes( 2 );
|
|
@@ -922,10 +914,10 @@ describe( 'useSelect', () => {
|
|
|
922
914
|
</AsyncModeProvider>
|
|
923
915
|
);
|
|
924
916
|
|
|
925
|
-
const
|
|
917
|
+
const { rerender } = render( <App async={ true } /> );
|
|
926
918
|
|
|
927
919
|
// Ensure expected state was rendered.
|
|
928
|
-
expect(
|
|
920
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0' );
|
|
929
921
|
|
|
930
922
|
// Schedules an async update of the component.
|
|
931
923
|
act( () => {
|
|
@@ -933,13 +925,13 @@ describe( 'useSelect', () => {
|
|
|
933
925
|
} );
|
|
934
926
|
|
|
935
927
|
// Ensure the async update wasn't processed yet.
|
|
936
|
-
expect(
|
|
928
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0' );
|
|
937
929
|
|
|
938
930
|
// Switch from async mode to sync.
|
|
939
|
-
|
|
931
|
+
rerender( <App async={ false } /> );
|
|
940
932
|
|
|
941
933
|
// Ensure the async update was flushed during the rerender.
|
|
942
|
-
expect(
|
|
934
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '1' );
|
|
943
935
|
|
|
944
936
|
// initial render + subscription check + rerender with isAsync=false
|
|
945
937
|
expect( selectSpy ).toHaveBeenCalledTimes( 3 );
|
|
@@ -970,10 +962,10 @@ describe( 'useSelect', () => {
|
|
|
970
962
|
</AsyncModeProvider>
|
|
971
963
|
);
|
|
972
964
|
|
|
973
|
-
const
|
|
965
|
+
const { rerender } = render( <App variant="a" /> );
|
|
974
966
|
|
|
975
967
|
// Ensure expected state was rendered.
|
|
976
|
-
expect(
|
|
968
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'a:0' );
|
|
977
969
|
|
|
978
970
|
// Schedules an async update of the component.
|
|
979
971
|
act( () => {
|
|
@@ -981,13 +973,13 @@ describe( 'useSelect', () => {
|
|
|
981
973
|
} );
|
|
982
974
|
|
|
983
975
|
// Ensure the async update wasn't processed yet.
|
|
984
|
-
expect(
|
|
976
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'a:0' );
|
|
985
977
|
|
|
986
978
|
// Rerender with a prop change that causes dependency change.
|
|
987
|
-
|
|
979
|
+
rerender( <App variant="b" /> );
|
|
988
980
|
|
|
989
981
|
// Ensure the async update was flushed (cancelled) during the rerender.
|
|
990
|
-
expect(
|
|
982
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'b:1' );
|
|
991
983
|
|
|
992
984
|
// Give the async update time to run in case it wasn't cancelled
|
|
993
985
|
await new Promise( setImmediate );
|
|
@@ -1015,10 +1007,10 @@ describe( 'useSelect', () => {
|
|
|
1015
1007
|
</AsyncModeProvider>
|
|
1016
1008
|
);
|
|
1017
1009
|
|
|
1018
|
-
const
|
|
1010
|
+
const { unmount } = render( <App /> );
|
|
1019
1011
|
|
|
1020
1012
|
// Ensure expected state was rendered.
|
|
1021
|
-
expect(
|
|
1013
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0' );
|
|
1022
1014
|
|
|
1023
1015
|
// Schedules an async update of the component.
|
|
1024
1016
|
act( () => {
|
|
@@ -1026,10 +1018,10 @@ describe( 'useSelect', () => {
|
|
|
1026
1018
|
} );
|
|
1027
1019
|
|
|
1028
1020
|
// Ensure the async update wasn't processed yet.
|
|
1029
|
-
expect(
|
|
1021
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0' );
|
|
1030
1022
|
|
|
1031
1023
|
// Unmount
|
|
1032
|
-
|
|
1024
|
+
unmount();
|
|
1033
1025
|
|
|
1034
1026
|
// Give the async update time to run in case it wasn't cancelled
|
|
1035
1027
|
await new Promise( setImmediate );
|
|
@@ -1060,19 +1052,19 @@ describe( 'useSelect', () => {
|
|
|
1060
1052
|
</AsyncModeProvider>
|
|
1061
1053
|
);
|
|
1062
1054
|
|
|
1063
|
-
const
|
|
1055
|
+
const { rerender } = render( <App reg={ registry } /> );
|
|
1064
1056
|
|
|
1065
|
-
expect(
|
|
1057
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0' );
|
|
1066
1058
|
|
|
1067
1059
|
act( () => {
|
|
1068
1060
|
registry.dispatch( 'counter' ).inc();
|
|
1069
1061
|
} );
|
|
1070
1062
|
|
|
1071
|
-
expect(
|
|
1063
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '0' );
|
|
1072
1064
|
|
|
1073
|
-
|
|
1065
|
+
rerender( <App reg={ registry2 } /> );
|
|
1074
1066
|
|
|
1075
|
-
expect(
|
|
1067
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '100' );
|
|
1076
1068
|
|
|
1077
1069
|
// Give the async update time to run in case it wasn't cancelled
|
|
1078
1070
|
await new Promise( setImmediate );
|
|
@@ -1108,13 +1100,13 @@ describe( 'useSelect', () => {
|
|
|
1108
1100
|
</RegistryProvider>
|
|
1109
1101
|
);
|
|
1110
1102
|
|
|
1111
|
-
const
|
|
1112
|
-
expect(
|
|
1103
|
+
const { rerender } = render( <App multiple={ 1 } /> );
|
|
1104
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '1' );
|
|
1113
1105
|
|
|
1114
1106
|
// Check that the most recent value of `multiple` is used to render:
|
|
1115
1107
|
// the old callback wasn't memoized and there is no stale closure problem.
|
|
1116
|
-
|
|
1117
|
-
expect(
|
|
1108
|
+
rerender( <App multiple={ 2 } /> );
|
|
1109
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '2' );
|
|
1118
1110
|
} );
|
|
1119
1111
|
|
|
1120
1112
|
it( 'subscribes only stores used by the initial callback', () => {
|
|
@@ -1133,24 +1125,24 @@ describe( 'useSelect', () => {
|
|
|
1133
1125
|
);
|
|
1134
1126
|
|
|
1135
1127
|
// initial render with counter-1
|
|
1136
|
-
const
|
|
1137
|
-
expect(
|
|
1128
|
+
const { rerender } = render( <App store="counter-1" /> );
|
|
1129
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '1' );
|
|
1138
1130
|
|
|
1139
1131
|
// update from counter-1
|
|
1140
1132
|
act( () => {
|
|
1141
1133
|
registry.dispatch( 'counter-1' ).inc();
|
|
1142
1134
|
} );
|
|
1143
|
-
expect(
|
|
1135
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '2' );
|
|
1144
1136
|
|
|
1145
1137
|
// rerender with counter-2
|
|
1146
|
-
|
|
1147
|
-
expect(
|
|
1138
|
+
rerender( <App store="counter-2" /> );
|
|
1139
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '10' );
|
|
1148
1140
|
|
|
1149
1141
|
// update from counter-2 is ignored because component is subcribed only to counter-1
|
|
1150
1142
|
act( () => {
|
|
1151
1143
|
registry.dispatch( 'counter-2' ).inc();
|
|
1152
1144
|
} );
|
|
1153
|
-
expect(
|
|
1145
|
+
expect( screen.getByRole( 'status' ) ).toHaveTextContent( '10' );
|
|
1154
1146
|
} );
|
|
1155
1147
|
} );
|
|
1156
1148
|
} );
|