@@ -2,30 +2,20 @@ import { calcFactorial } from '../Factorial'
2
2
3
3
describe ( 'calcFactorial' , ( ) => {
4
4
it ( 'should return a statement for value "0"' , ( ) => {
5
- expect ( calcFactorial ( 0 ) ) . toBe ( 'The factorial of 0 is 1.' )
5
+ expect ( calcFactorial ( 0 ) ) . toBe ( 1 )
6
6
} )
7
7
8
- it ( 'should return a statement for "null" and "undefined"' , ( ) => {
9
- const nullFactorial = calcFactorial ( null )
10
- const undefinedFactorial = calcFactorial ( undefined )
11
-
12
- expect ( nullFactorial ) . toBe (
13
- 'Sorry, factorial does not exist for null or undefined numbers.'
14
- )
15
- expect ( undefinedFactorial ) . toBe (
16
- 'Sorry, factorial does not exist for null or undefined numbers.'
17
- )
8
+ it ( 'should throw error for "null" and "undefined"' , ( ) => {
9
+ expect ( ( ) => { calcFactorial ( null ) } ) . toThrow ( Error )
10
+ expect ( ( ) => { calcFactorial ( undefined ) } ) . toThrow ( Error )
18
11
} )
19
12
20
- it ( 'should not support negative numbers' , ( ) => {
21
- const negativeFactorial = calcFactorial ( - 5 )
22
- expect ( negativeFactorial ) . toBe (
23
- 'Sorry, factorial does not exist for negative numbers.'
24
- )
13
+ it ( 'should throw error for negative numbers' , ( ) => {
14
+ expect ( ( ) => { calcFactorial ( - 1 ) } ) . toThrow ( Error )
25
15
} )
26
16
27
17
it ( 'should return the factorial of a positive number' , ( ) => {
28
18
const positiveFactorial = calcFactorial ( 3 )
29
- expect ( positiveFactorial ) . toBe ( 'The factorial of 3 is 6' )
19
+ expect ( positiveFactorial ) . toBe ( 6 )
30
20
} )
31
21
} )
0 commit comments