1
1
import { checkValidAyahId , meta } from "../src"
2
2
3
3
describe ( "checkValidAyahId" , ( ) => {
4
- it ( "should return true for valid ayah id" , ( ) => {
5
- expect ( checkValidAyahId ( 1 ) ) . toBe ( true )
6
- expect ( checkValidAyahId ( meta . numAyas ) ) . toBe ( true )
7
- expect ( checkValidAyahId ( Math . floor ( meta . numAyas / 2 ) ) ) . toBe ( true )
8
- } )
9
-
10
4
it ( "should throw RangeError for ayah id less than 1" , ( ) => {
11
5
expect ( ( ) => checkValidAyahId ( 0 ) ) . toThrow ( RangeError )
12
6
expect ( ( ) => checkValidAyahId ( - 1 ) ) . toThrow ( RangeError )
@@ -17,14 +11,42 @@ describe("checkValidAyahId", () => {
17
11
expect ( ( ) => checkValidAyahId ( Number . MAX_SAFE_INTEGER ) ) . toThrow ( RangeError )
18
12
} )
19
13
20
- // it("should throw RangeError for non-integer ayah id", () => {
21
- // expect(() => checkValidAyahId(1.5)).toThrow(RangeError);
22
- // expect(() => checkValidAyahId(2.99)).toThrow(RangeError);
23
- // });
14
+ it ( "should throw TypeError for non-integer ayah id" , ( ) => {
15
+ expect ( ( ) => checkValidAyahId ( 1.5 ) ) . toThrow ( TypeError )
16
+ expect ( ( ) => checkValidAyahId ( 2.99 ) ) . toThrow ( TypeError )
17
+ expect ( ( ) => checkValidAyahId ( Math . PI ) ) . toThrow ( TypeError )
18
+ } )
19
+
20
+ it ( "should throw TypeError for NaN" , ( ) => {
21
+ expect ( ( ) => checkValidAyahId ( NaN ) ) . toThrow ( TypeError )
22
+ } )
23
+
24
+ it ( "should throw TypeError for Infinity" , ( ) => {
25
+ expect ( ( ) => checkValidAyahId ( Infinity ) ) . toThrow ( TypeError )
26
+ expect ( ( ) => checkValidAyahId ( - Infinity ) ) . toThrow ( TypeError )
27
+ } )
28
+
29
+ it ( "should handle checkOnly" , ( ) => {
30
+ expect ( checkValidAyahId ( 1 , true ) ) . toBe ( true )
31
+ expect ( checkValidAyahId ( meta . numAyas , true ) ) . toBe ( true )
32
+ expect ( checkValidAyahId ( Math . floor ( meta . numAyas / 2 ) , true ) ) . toBe ( true )
33
+ expect ( checkValidAyahId ( 0 , true ) ) . toBe ( false )
34
+ expect ( checkValidAyahId ( meta . numAyas + 1 , true ) ) . toBe ( false )
35
+ expect ( checkValidAyahId ( 1.5 , true ) ) . toBe ( false )
36
+ expect ( checkValidAyahId ( NaN , true ) ) . toBe ( false )
37
+ expect ( checkValidAyahId ( Infinity , true ) ) . toBe ( false )
38
+ } )
24
39
25
- // it("should throw TypeError for non-number ayah id", () => {
26
- // expect(() => checkValidAyahId("1" as any)).toThrow(TypeError);
27
- // expect(() => checkValidAyahId(null as any)).toThrow(TypeError);
28
- // expect(() => checkValidAyahId(undefined as any)).toThrow(TypeError);
29
- // });
40
+ it ( "should handle edge cases correctly" , ( ) => {
41
+ expect ( checkValidAyahId ( 1 ) ) . toBe ( true )
42
+ expect ( checkValidAyahId ( meta . numAyas ) ) . toBe ( true )
43
+ expect ( ( ) => checkValidAyahId ( meta . numAyas + 0.5 ) ) . toThrow ( TypeError )
44
+ expect ( checkValidAyahId ( Math . floor ( meta . numAyas / 2 ) ) ) . toBe ( true )
45
+ } )
46
+
47
+ it ( "should throw TypeError for non-number ayah id" , ( ) => {
48
+ expect ( ( ) => checkValidAyahId ( "1" as any ) ) . toThrow ( TypeError )
49
+ expect ( ( ) => checkValidAyahId ( null as any ) ) . toThrow ( TypeError )
50
+ expect ( ( ) => checkValidAyahId ( undefined as any ) ) . toThrow ( TypeError )
51
+ } )
30
52
} )
0 commit comments