@@ -27,7 +27,13 @@ describe('Shared utils', () => {
27
27
it ( 'should return false when object is not undefined' , ( ) => {
28
28
expect ( isUndefined ( { } ) ) . to . be . false ;
29
29
} ) ;
30
+ it ( 'should return false for falsy values like false, 0, or empty string' , ( ) => {
31
+ expect ( isUndefined ( false ) ) . to . be . false ;
32
+ expect ( isUndefined ( 0 ) ) . to . be . false ;
33
+ expect ( isUndefined ( '' ) ) . to . be . false ;
34
+ } ) ;
30
35
} ) ;
36
+
31
37
describe ( 'isFunction' , ( ) => {
32
38
it ( 'should return true when obj is function' , ( ) => {
33
39
expect ( isFunction ( ( ) => ( { } ) ) ) . to . be . true ;
@@ -37,16 +43,21 @@ describe('Shared utils', () => {
37
43
expect ( isFunction ( undefined ) ) . to . be . false ;
38
44
} ) ;
39
45
} ) ;
46
+
40
47
describe ( 'isObject' , ( ) => {
41
48
it ( 'should return true when obj is object' , ( ) => {
42
49
expect ( isObject ( { } ) ) . to . be . true ;
43
50
} ) ;
51
+ it ( 'should return true for arrays' , ( ) => {
52
+ expect ( isObject ( [ 1 , 2 , 3 ] ) ) . to . be . true ; // Arrays are objects
53
+ } ) ;
44
54
it ( 'should return false when object is not object' , ( ) => {
45
55
expect ( isObject ( 3 ) ) . to . be . false ;
46
56
expect ( isObject ( null ) ) . to . be . false ;
47
57
expect ( isObject ( undefined ) ) . to . be . false ;
48
58
} ) ;
49
59
} ) ;
60
+
50
61
describe ( 'isPlainObject' , ( ) => {
51
62
it ( 'should return true when obj is plain object' , ( ) => {
52
63
expect ( isPlainObject ( { } ) ) . to . be . true ;
@@ -66,7 +77,12 @@ describe('Shared utils', () => {
66
77
expect ( isPlainObject ( new Date ( ) ) ) . to . be . false ;
67
78
expect ( isPlainObject ( new Foo ( 1 ) ) ) . to . be . false ;
68
79
} ) ;
80
+ it ( 'should return false for objects with custom prototypes' , ( ) => {
81
+ function CustomObject ( ) { }
82
+ expect ( isPlainObject ( new CustomObject ( ) ) ) . to . be . false ;
83
+ } ) ;
69
84
} ) ;
85
+
70
86
describe ( 'isString' , ( ) => {
71
87
it ( 'should return true when val is a string' , ( ) => {
72
88
expect ( isString ( 'true' ) ) . to . be . true ;
@@ -78,6 +94,7 @@ describe('Shared utils', () => {
78
94
expect ( isString ( undefined ) ) . to . be . false ;
79
95
} ) ;
80
96
} ) ;
97
+
81
98
describe ( 'isSymbol' , ( ) => {
82
99
it ( 'should return true when val is a Symbol' , ( ) => {
83
100
expect ( isSymbol ( Symbol ( ) ) ) . to . be . true ;
@@ -88,7 +105,11 @@ describe('Shared utils', () => {
88
105
expect ( isSymbol ( null ) ) . to . be . false ;
89
106
expect ( isSymbol ( undefined ) ) . to . be . false ;
90
107
} ) ;
108
+ it ( 'should return false for invalid Symbol objects' , ( ) => {
109
+ expect ( isSymbol ( Object ( Symbol ( ) ) ) ) . to . be . false ;
110
+ } ) ;
91
111
} ) ;
112
+
92
113
describe ( 'isNumber' , ( ) => {
93
114
it ( 'should return true when val is a number or NaN' , ( ) => {
94
115
expect ( isNumber ( 1 ) ) . to . be . true ;
@@ -98,22 +119,32 @@ describe('Shared utils', () => {
98
119
expect ( isNumber ( 0b1 ) ) . to . be . true ; // binary notation
99
120
expect ( isNumber ( 0x1 ) ) . to . be . true ; // hexadecimal notation
100
121
expect ( isNumber ( NaN ) ) . to . be . true ;
122
+ expect ( isNumber ( Infinity ) ) . to . be . true ;
123
+ expect ( isNumber ( - Infinity ) ) . to . be . true ;
101
124
} ) ;
102
125
it ( 'should return false when val is not a number' , ( ) => {
103
126
// expect(isNumber(1n)).to.be.false; // big int (available on ES2020)
104
127
expect ( isNumber ( '1' ) ) . to . be . false ; // string
105
128
expect ( isNumber ( undefined ) ) . to . be . false ; // nullish
106
129
expect ( isNumber ( null ) ) . to . be . false ; // nullish
130
+ expect ( isNumber ( new Number ( 123 ) ) ) . to . be . false ; // number
107
131
} ) ;
108
132
} ) ;
133
+
109
134
describe ( 'isConstructor' , ( ) => {
110
135
it ( 'should return true when string is equal to constructor' , ( ) => {
111
136
expect ( isConstructor ( 'constructor' ) ) . to . be . true ;
112
137
} ) ;
113
138
it ( 'should return false when string is not equal to constructor' , ( ) => {
114
139
expect ( isConstructor ( 'nope' ) ) . to . be . false ;
115
140
} ) ;
141
+ it ( 'should return false for non-string values' , ( ) => {
142
+ expect ( isConstructor ( null ) ) . to . be . false ;
143
+ expect ( isConstructor ( undefined ) ) . to . be . false ;
144
+ expect ( isConstructor ( 123 ) ) . to . be . false ;
145
+ } ) ;
116
146
} ) ;
147
+
117
148
describe ( 'addLeadingSlash' , ( ) => {
118
149
it ( 'should return the validated path ("add / if not exists")' , ( ) => {
119
150
expect ( addLeadingSlash ( 'nope' ) ) . to . be . eql ( '/nope' ) ;
@@ -128,7 +159,13 @@ describe('Shared utils', () => {
128
159
expect ( addLeadingSlash ( null ! ) ) . to . be . eql ( '' ) ;
129
160
expect ( addLeadingSlash ( undefined ) ) . to . be . eql ( '' ) ;
130
161
} ) ;
162
+ it ( 'should handle paths with special characters' , ( ) => {
163
+ expect ( addLeadingSlash ( 'path-with-special-chars!@#$%^&*()' ) ) . to . eql (
164
+ '/path-with-special-chars!@#$%^&*()' ,
165
+ ) ;
166
+ } ) ;
131
167
} ) ;
168
+
132
169
describe ( 'normalizePath' , ( ) => {
133
170
it ( 'should remove all trailing slashes at the end of the path' , ( ) => {
134
171
expect ( normalizePath ( 'path/' ) ) . to . be . eql ( '/path' ) ;
@@ -146,6 +183,7 @@ describe('Shared utils', () => {
146
183
expect ( normalizePath ( undefined ) ) . to . be . eql ( '/' ) ;
147
184
} ) ;
148
185
} ) ;
186
+
149
187
describe ( 'isNil' , ( ) => {
150
188
it ( 'should return true when obj is undefined or null' , ( ) => {
151
189
expect ( isNil ( undefined ) ) . to . be . true ;
@@ -154,7 +192,13 @@ describe('Shared utils', () => {
154
192
it ( 'should return false when object is not undefined and null' , ( ) => {
155
193
expect ( isNil ( '3' ) ) . to . be . false ;
156
194
} ) ;
195
+ it ( 'should return false for falsy values like false, 0, or empty string' , ( ) => {
196
+ expect ( isNil ( false ) ) . to . be . false ;
197
+ expect ( isNil ( 0 ) ) . to . be . false ;
198
+ expect ( isNil ( '' ) ) . to . be . false ;
199
+ } ) ;
157
200
} ) ;
201
+
158
202
describe ( 'isEmpty' , ( ) => {
159
203
it ( 'should return true when array is empty or not exists' , ( ) => {
160
204
expect ( isEmpty ( [ ] ) ) . to . be . true ;
@@ -164,10 +208,19 @@ describe('Shared utils', () => {
164
208
it ( 'should return false when array is not empty' , ( ) => {
165
209
expect ( isEmpty ( [ 1 , 2 ] ) ) . to . be . false ;
166
210
} ) ;
211
+ it ( 'should return true for non-array values' , ( ) => {
212
+ expect ( isEmpty ( { } ) ) . to . be . true ;
213
+ expect ( isEmpty ( '' ) ) . to . be . true ;
214
+ expect ( isEmpty ( 0 ) ) . to . be . true ;
215
+ expect ( isEmpty ( false ) ) . to . be . true ;
216
+ } ) ;
167
217
} ) ;
218
+
168
219
describe ( 'stripEndSlash' , ( ) => {
169
220
it ( 'should strip end slash if present' , ( ) => {
170
221
expect ( stripEndSlash ( '/cats/' ) ) . to . equal ( '/cats' ) ;
222
+ } ) ;
223
+ it ( 'should return the same path if no trailing slash exists' , ( ) => {
171
224
expect ( stripEndSlash ( '/cats' ) ) . to . equal ( '/cats' ) ;
172
225
} ) ;
173
226
} ) ;
0 commit comments