@@ -2,30 +2,20 @@ import { calcFactorial } from '../Factorial'
22
33describe ( 'calcFactorial' , ( ) => {
44 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 )
66 } )
77
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 )
1811 } )
1912
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 )
2515 } )
2616
2717 it ( 'should return the factorial of a positive number' , ( ) => {
2818 const positiveFactorial = calcFactorial ( 3 )
29- expect ( positiveFactorial ) . toBe ( 'The factorial of 3 is 6' )
19+ expect ( positiveFactorial ) . toBe ( 6 )
3020 } )
3121} )
0 commit comments