@@ -155,4 +155,112 @@ Deno.test("isStrictOf<T>", async (t) => {
155
155
}
156
156
} ) ;
157
157
} ) ;
158
+
159
+ await t . step ( "with symbol properties" , async ( t ) => {
160
+ const b = Symbol ( "b" ) ;
161
+ const c = Symbol ( "c" ) ;
162
+ const predObj = {
163
+ a : is . Number ,
164
+ [ b ] : is . UnionOf ( [ is . String , is . Undefined ] ) ,
165
+ [ c ] : as . Optional ( is . Boolean ) ,
166
+ } ;
167
+ await t . step ( "returns properly named predicate function" , async ( t ) => {
168
+ await assertSnapshot (
169
+ t ,
170
+ isStrictOf (
171
+ is . ObjectOf ( { a : is . Number , [ b ] : is . String , [ c ] : is . Boolean } ) ,
172
+ )
173
+ . name ,
174
+ ) ;
175
+ await assertSnapshot (
176
+ t ,
177
+ isStrictOf (
178
+ is . ObjectOf ( {
179
+ a : isStrictOf (
180
+ is . ObjectOf ( {
181
+ [ b ] : isStrictOf ( is . ObjectOf ( { [ c ] : is . Boolean } ) ) ,
182
+ } ) ,
183
+ ) ,
184
+ } ) ,
185
+ ) . name ,
186
+ ) ;
187
+ } ) ;
188
+
189
+ await t . step ( "returns true on T object" , ( ) => {
190
+ assertEquals (
191
+ isStrictOf ( is . ObjectOf ( predObj ) ) ( { a : 0 , [ b ] : "a" , [ c ] : true } ) ,
192
+ true ,
193
+ ) ;
194
+ assertEquals (
195
+ isStrictOf ( is . ObjectOf ( predObj ) ) ( { a : 0 , [ b ] : "a" } ) ,
196
+ true ,
197
+ "Object does not have an optional property" ,
198
+ ) ;
199
+ assertEquals (
200
+ isStrictOf ( is . ObjectOf ( predObj ) ) ( { a : 0 , [ b ] : "a" , [ c ] : undefined } ) ,
201
+ true ,
202
+ "Object has `undefined` as value of optional property" ,
203
+ ) ;
204
+ } ) ;
205
+
206
+ await t . step ( "returns false on non T object" , ( ) => {
207
+ assertEquals (
208
+ isStrictOf ( is . ObjectOf ( predObj ) ) ( { a : 0 , [ b ] : "a" , [ c ] : "" } ) ,
209
+ false ,
210
+ "Object have a different type property" ,
211
+ ) ;
212
+ assertEquals (
213
+ isStrictOf ( is . ObjectOf ( predObj ) ) ( { a : 0 , [ b ] : "a" , [ c ] : null } ) ,
214
+ false ,
215
+ "Object has `null` as value of optional property" ,
216
+ ) ;
217
+ assertEquals (
218
+ isStrictOf ( is . ObjectOf ( predObj ) ) ( {
219
+ a : 0 ,
220
+ [ b ] : "a" ,
221
+ [ c ] : true ,
222
+ d : "invalid" ,
223
+ } ) ,
224
+ false ,
225
+ "Object have an unknown property" ,
226
+ ) ;
227
+ assertEquals (
228
+ isStrictOf ( is . ObjectOf ( predObj ) ) ( {
229
+ a : 0 ,
230
+ [ b ] : "a" ,
231
+ [ c ] : true ,
232
+ [ Symbol ( "d" ) ] : "invalid" ,
233
+ } ) ,
234
+ false ,
235
+ "Object have an unknown symbol property" ,
236
+ ) ;
237
+ assertEquals (
238
+ isStrictOf ( is . ObjectOf ( predObj ) ) ( {
239
+ a : 0 ,
240
+ [ b ] : "a" ,
241
+ d : "invalid" ,
242
+ } ) ,
243
+ false ,
244
+ "Object have the same number of properties but an unknown property exists" ,
245
+ ) ;
246
+ assertEquals (
247
+ isStrictOf ( is . ObjectOf ( predObj ) ) ( {
248
+ a : 0 ,
249
+ [ b ] : "a" ,
250
+ [ Symbol ( "d" ) ] : "invalid" ,
251
+ } ) ,
252
+ false ,
253
+ "Object have the same number of properties but an unknown symbol property exists" ,
254
+ ) ;
255
+ } ) ;
256
+
257
+ await t . step ( "predicated type is correct" , ( ) => {
258
+ const a : unknown = { a : 0 , [ b ] : "a" } ;
259
+ if ( isStrictOf ( is . ObjectOf ( predObj ) ) ( a ) ) {
260
+ assertType <
261
+ Equal < typeof a , { a : number ; [ b ] : string | undefined ; [ c ] ?: boolean } >
262
+ > ( true ) ;
263
+ }
264
+ } ) ;
265
+ } ) ;
158
266
} ) ;
0 commit comments