Skip to content
Next Next commit
Adding tests for delay
  • Loading branch information
reficul31 committed Dec 24, 2017
commit ae08cf2de99558b9edc5e63bfcd54c2f4513050e
26 changes: 26 additions & 0 deletions src/util/delay.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import delay from './delay'

jest.useFakeTimers()

describe('delay', () => {
test('should set a timer with the given delay', () => {
delay(1000)
expect(setTimeout.mock.calls.length).toBe(1)
expect(setTimeout.mock.calls[0][1]).toBe(1000)
})

test('should return a promise which resolves after the timer finishes', async () => {
const assertFunc = jest.fn()
delay(1000)
.then(assertFunc)
.catch(err => {})

await null
expect(assertFunc).not.toHaveBeenCalled()

jest.runAllTimers()

await null
expect(assertFunc).toHaveBeenCalled()
})
})