forked from TheAlgorithms/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorial.test.js
More file actions
29 lines (26 loc) · 828 Bytes
/
Factorial.test.js
File metadata and controls
29 lines (26 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { factorial } from '../Factorial'
describe('Factorial', () => {
it('should return factorial 1 for value "0"', () => {
expect(factorial(0)).toBe(1)
})
it('should return factorial 120 for value "5"', () => {
expect(factorial(5)).toBe(120)
})
it('Throw Error for Invalid Input', () => {
expect(() => factorial('-')).toThrow(
'Input should be a non-negative whole number'
)
expect(() => factorial(null)).toThrow(
'Input should be a non-negative whole number'
)
expect(() => factorial(undefined)).toThrow(
'Input should be a non-negative whole number'
)
expect(() => factorial(3.142)).toThrow(
'Input should be a non-negative whole number'
)
expect(() => factorial(-1)).toThrow(
'Input should be a non-negative whole number'
)
})
})