Skip to main content
Module

x/rambda/source/waitFor.spec.js

Faster and smaller alternative to Ramda
Go to Latest
File
import {delay} from './delay'import {waitFor} from './waitFor'
const howLong = 1000
test('true', async () => { let counter = 0 const condition = x => { counter++
return counter > x }
const result = await waitFor(condition, howLong)(6) expect(result).toEqual(true)})
test('false', async () => { let counter = 0 const condition = x => { counter++
return counter > x }
const result = await waitFor(condition, howLong)(12) expect(result).toEqual(false)})
test('async condition | true', async () => { let counter = 0 const condition = async x => { counter++ await delay(10)
return counter > x }
const result = await waitFor(condition, howLong)(6) expect(result).toEqual(true)})
test('async condition | false', async () => { let counter = 0 const condition = async x => { counter++ await delay(10)
return counter > x }
const result = await waitFor(condition, howLong)(12) expect(result).toEqual(false)})
test('throws when fn is not function', () => { const fn = 'foo'
expect(() => waitFor(fn, howLong)()).toThrowWithMessage(Error, 'R.waitFor')})