Open History to see the last commit
1import { NotifyManager } from '../notifyManager'
2import { sleep } from '../../devtools/tests/utils'
3β
4describe('notifyManager', () => {
5 it('should use default notifyFn', async () => {
6 const notifyManagerTest = new NotifyManager()
7 const callbackSpy = jest.fn()
8 notifyManagerTest.schedule(callbackSpy)
9 await sleep(1)
10 expect(callbackSpy).toHaveBeenCalled()
11 })
12β
13 it('should use default batchNotifyFn', async () => {
14 const notifyManagerTest = new NotifyManager()
15 const callbackScheduleSpy = jest
16 .fn()
17 .mockImplementation(async () => await sleep(20))
18 const callbackBatchLevel2Spy = jest.fn().mockImplementation(async () => {
19 notifyManagerTest.schedule(callbackScheduleSpy)
20 })
21 const callbackBatchLevel1Spy = jest.fn().mockImplementation(async () => {
22 notifyManagerTest.batch(callbackBatchLevel2Spy)
23 })
24β
25 notifyManagerTest.batch(callbackBatchLevel1Spy)
26β
27 await sleep(30)
28 expect(callbackBatchLevel1Spy).toHaveBeenCalledTimes(1)
29 expect(callbackBatchLevel2Spy).toHaveBeenCalledTimes(1)
30 expect(callbackScheduleSpy).toHaveBeenCalledTimes(1)
31 })
32β
33 it('should flush if error is thrown', () => {
34 const notifyManagerTest = new NotifyManager()
35 const flushSpy = jest.fn()
36β
37 notifyManagerTest.flush = flushSpy
38β
39 try {
40 notifyManagerTest.batch(() => {
41 throw new Error('Foo')
42 })
43 } catch {}
44β
45 expect(flushSpy).toHaveBeenCalledTimes(1)
46 })
47})