vrandom
Version:
an easy way to work with random numbers in javascript
40 lines (35 loc) • 902 B
JavaScript
const flip = require('../lib/flip.js')
describe('flip', () => {
it('returns a boolean', () => {
const actual = flip()
expect(typeof actual).toBe('boolean')
})
it.each([
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ]
])('flip() should return %s when Math.random returns %f', (expected, mockValue) => {
jest.spyOn(Math, 'random').mockReturnValueOnce(mockValue)
const actual = flip()
expect(actual).toBe(expected)
Math.random.mockRestore()
})
})