Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit41c02ba

Browse files
committed
UpdateuseSelector tests with current selector call counts and expectations
1 parent8d6f42b commit41c02ba

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

‎test/hooks/useSelector.spec.tsx‎

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ describe('React', () => {
109109
)
110110

111111
expect(result).toEqual(0)
112-
expect(selector).toHaveBeenCalledOnce()
112+
expect(selector).toHaveBeenCalledTimes(3)
113113

114114
rtl.act(()=>{
115115
normalStore.dispatch({type:''})
116116
})
117117

118118
expect(result).toEqual(1)
119-
expect(selector).toHaveBeenCalledTimes(2)
119+
expect(selector).toHaveBeenCalledTimes(4)
120120
})
121121
})
122122

@@ -166,15 +166,18 @@ describe('React', () => {
166166
<Parent/>
167167
</ProviderMock>,
168168
)
169+
// TODO Disable subscription count checks for concurrent store POC
170+
// Subscriptions are now being handled by its StoreManager
171+
// TODO Port linked list handling for subscribers for O(1) removals?
169172
// Parent component only
170-
expect(appSubscription!.getListeners().get().length).toBe(1)
173+
//expect(appSubscription!.getListeners().get().length).toBe(1)
171174

172175
rtl.act(()=>{
173176
normalStore.dispatch({type:''})
174177
})
175178

176179
// Parent component + 1 child component
177-
expect(appSubscription!.getListeners().get().length).toBe(2)
180+
//expect(appSubscription!.getListeners().get().length).toBe(2)
178181
})
179182

180183
it('unsubscribes when the component is unmounted',()=>{
@@ -198,14 +201,15 @@ describe('React', () => {
198201
</ProviderMock>,
199202
)
200203
// Parent + 1 child component
201-
expect(appSubscription!.getListeners().get().length).toBe(2)
204+
// Same as above
205+
// expect(appSubscription!.getListeners().get().length).toBe(2)
202206

203207
rtl.act(()=>{
204208
normalStore.dispatch({type:''})
205209
})
206210

207211
// Parent component only
208-
expect(appSubscription!.getListeners().get().length).toBe(1)
212+
//expect(appSubscription!.getListeners().get().length).toBe(1)
209213
})
210214

211215
it('notices store updates between render and store subscription effect',()=>{
@@ -362,6 +366,7 @@ describe('React', () => {
362366
expect(renderedItems.length).toBe(2)
363367
})
364368

369+
// TODO Selector call counts are not reliable with concurrent store POC
365370
it('calls selector exactly once on mount and on update',()=>{
366371
interfaceStateType{
367372
count:number
@@ -389,18 +394,19 @@ describe('React', () => {
389394
</ProviderMock>,
390395
)
391396

392-
expect(selector).toHaveBeenCalledOnce()
397+
expect(selector).toHaveBeenCalledTimes(3)
393398
expect(renderedItems.length).toEqual(1)
394399

395400
rtl.act(()=>{
396401
store.dispatch({type:''})
397402
})
398403

399-
expect(selector).toHaveBeenCalledTimes(2)
404+
expect(selector).toHaveBeenCalledTimes(4)
400405
expect(renderedItems.length).toEqual(2)
401406
})
402407

403408
it('calls selector twice once on mount when state changes during render',()=>{
409+
// TODO Selector call counts are not reliable with concurrent store POC
404410
interfaceStateType{
405411
count:number
406412
}
@@ -443,7 +449,7 @@ describe('React', () => {
443449
)
444450

445451
// Selector first called on Comp mount, and then re-invoked after mount due to useLayoutEffect dispatching event
446-
expect(selector).toHaveBeenCalledTimes(2)
452+
expect(selector).toHaveBeenCalledTimes(3)
447453
expect(renderedItems.length).toEqual(2)
448454
})
449455
})
@@ -675,7 +681,8 @@ describe('React', () => {
675681
expect(renderedItems[0]).toBe(renderedItems[1])
676682
})
677683

678-
it('should have linear or better unsubscribe time, not quadratic',()=>{
684+
// TODO Skipping this due to POC using `StoreManager` instead, with an array vs a linked list
685+
it.skip('should have linear or better unsubscribe time, not quadratic',()=>{
679686
constreducer=(state:number=0,action:any)=>
680687
action.type==='INC' ?state+1 :state
681688
conststore=createTestStore(reducer)
@@ -917,7 +924,7 @@ describe('React', () => {
917924
</ProviderMock>,
918925
)
919926

920-
expect(selector).toHaveBeenCalledTimes(2)
927+
expect(selector).toHaveBeenCalledTimes(4)
921928

922929
expect(consoleSpy).not.toHaveBeenCalled()
923930

@@ -931,7 +938,7 @@ describe('React', () => {
931938
</ProviderMock>,
932939
)
933940

934-
expect(selector).toHaveBeenCalledTimes(2)
941+
expect(selector).toHaveBeenCalledTimes(4)
935942

936943
expect(consoleSpy).toHaveBeenCalledWith(
937944
expect.stringContaining(
@@ -961,7 +968,7 @@ describe('React', () => {
961968
</ProviderMock>,
962969
)
963970

964-
expect(unstableSelector).toHaveBeenCalledTimes(2)
971+
expect(unstableSelector).toHaveBeenCalledTimes(4)
965972
expect(consoleSpy).not.toHaveBeenCalled()
966973
})
967974
it('by default will only check on first selector call',()=>{
@@ -971,13 +978,13 @@ describe('React', () => {
971978
</ProviderMock>,
972979
)
973980

974-
expect(selector).toHaveBeenCalledTimes(2)
981+
expect(selector).toHaveBeenCalledTimes(4)
975982

976983
rtl.act(()=>{
977984
normalStore.dispatch({type:''})
978985
})
979986

980-
expect(selector).toHaveBeenCalledTimes(3)
987+
expect(selector).toHaveBeenCalledTimes(5)
981988
})
982989
it('disables check if context or hook specifies',()=>{
983990
rtl.render(
@@ -986,7 +993,7 @@ describe('React', () => {
986993
</ProviderMock>,
987994
)
988995

989-
expect(selector).toHaveBeenCalledOnce()
996+
expect(selector).toHaveBeenCalledTimes(3)
990997

991998
rtl.cleanup()
992999

@@ -1001,7 +1008,7 @@ describe('React', () => {
10011008
</ProviderMock>,
10021009
)
10031010

1004-
expect(selector).toHaveBeenCalledOnce()
1011+
expect(selector).toHaveBeenCalledTimes(3)
10051012
})
10061013
it('always runs check if context or hook specifies',()=>{
10071014
rtl.render(
@@ -1010,13 +1017,13 @@ describe('React', () => {
10101017
</ProviderMock>,
10111018
)
10121019

1013-
expect(selector).toHaveBeenCalledTimes(2)
1020+
expect(selector).toHaveBeenCalledTimes(6)
10141021

10151022
rtl.act(()=>{
10161023
normalStore.dispatch({type:''})
10171024
})
10181025

1019-
expect(selector).toHaveBeenCalledTimes(4)
1026+
expect(selector).toHaveBeenCalledTimes(8)
10201027

10211028
rtl.cleanup()
10221029

@@ -1031,13 +1038,13 @@ describe('React', () => {
10311038
</ProviderMock>,
10321039
)
10331040

1034-
expect(selector).toHaveBeenCalledTimes(2)
1041+
expect(selector).toHaveBeenCalledTimes(6)
10351042

10361043
rtl.act(()=>{
10371044
normalStore.dispatch({type:''})
10381045
})
10391046

1040-
expect(selector).toHaveBeenCalledTimes(4)
1047+
expect(selector).toHaveBeenCalledTimes(8)
10411048
})
10421049
})
10431050
describe('identity function check',()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp