File tree 1 file changed +34
-0
lines changed
packages/query-core/src/__tests__
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -86,4 +86,38 @@ describe('notifyManager', () => {
86
86
// @ts -expect-error
87
87
someFn ( 'im not happy' , false )
88
88
} )
89
+
90
+ it ( 'should use custom batch notify function' , async ( ) => {
91
+ const notifyManagerTest = createNotifyManager ( )
92
+ const batchNotifySpy = vi . fn ( ( cb ) => cb ( ) )
93
+ const callbackSpy1 = vi . fn ( )
94
+ const callbackSpy2 = vi . fn ( )
95
+
96
+ notifyManagerTest . setBatchNotifyFunction ( batchNotifySpy )
97
+
98
+ notifyManagerTest . batch ( ( ) => {
99
+ notifyManagerTest . schedule ( callbackSpy1 )
100
+ notifyManagerTest . schedule ( callbackSpy2 )
101
+ } )
102
+
103
+ await vi . advanceTimersByTimeAsync ( 0 )
104
+
105
+ expect ( batchNotifySpy ) . toHaveBeenCalled ( )
106
+ expect ( callbackSpy1 ) . toHaveBeenCalled ( )
107
+ expect ( callbackSpy2 ) . toHaveBeenCalled ( )
108
+ } )
109
+
110
+ it ( 'should batch calls correctly' , async ( ) => {
111
+ const notifyManagerTest = createNotifyManager ( )
112
+ const callbackSpy = vi . fn ( )
113
+
114
+ const batchedFn = notifyManagerTest . batchCalls ( ( a : number , b : string ) => {
115
+ callbackSpy ( a , b )
116
+ } )
117
+
118
+ batchedFn ( 1 , 'test' )
119
+ await vi . advanceTimersByTimeAsync ( 0 )
120
+
121
+ expect ( callbackSpy ) . toHaveBeenCalledWith ( 1 , 'test' )
122
+ } )
89
123
} )
You can’t perform that action at this time.
0 commit comments