Skip to content

Commit 3bf217d

Browse files
authored
test(query-core): add test case for notifyManager (#8976)
1 parent efe6ddb commit 3bf217d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

packages/query-core/src/__tests__/notifyManager.test.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,38 @@ describe('notifyManager', () => {
8686
// @ts-expect-error
8787
someFn('im not happy', false)
8888
})
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+
})
89123
})

0 commit comments

Comments
 (0)