SIGN IN SIGN UP

Algorithms and Data Structures implemented in JavaScript for beginners, following best practices.

0 0 0 JavaScript
import { calcFactorial } from '../Factorial'
describe('calcFactorial', () => {
it('should return a statement for value "0"', () => {
2022-09-07 15:00:35 +05:30
expect(calcFactorial(0)).toBe(1)
})
2022-09-07 15:00:35 +05:30
it('should throw error for "null" and "undefined"', () => {
expect(() => {
calcFactorial(null)
}).toThrow(Error)
expect(() => {
calcFactorial(undefined)
}).toThrow(Error)
})
2022-09-07 15:00:35 +05:30
it('should throw error for negative numbers', () => {
expect(() => {
calcFactorial(-1)
}).toThrow(Error)
})
it('should return the factorial of a positive number', () => {
const positiveFactorial = calcFactorial(3)
2022-09-07 15:00:35 +05:30
expect(positiveFactorial).toBe(6)
})
})