@@ -44,7 +44,7 @@ function createMatcher(expectation, message) {
44
44
45
45
if ( arguments . length > 2 ) {
46
46
throw new TypeError (
47
- `Expected 1 or 2 arguments, received ${ arguments . length } `
47
+ `Expected 1 or 2 arguments, received ${ arguments . length } ` ,
48
48
) ;
49
49
}
50
50
@@ -89,21 +89,27 @@ createMatcher.falsy = createMatcher(function (actual) {
89
89
} , "falsy" ) ;
90
90
91
91
createMatcher . same = function ( expectation ) {
92
- return createMatcher ( function ( actual ) {
93
- return expectation === actual ;
94
- } , `same(${ valueToString ( expectation ) } )` ) ;
92
+ return createMatcher (
93
+ function ( actual ) {
94
+ return expectation === actual ;
95
+ } ,
96
+ `same(${ valueToString ( expectation ) } )` ,
97
+ ) ;
95
98
} ;
96
99
97
100
createMatcher . in = function ( arrayOfExpectations ) {
98
101
if ( typeOf ( arrayOfExpectations ) !== "array" ) {
99
102
throw new TypeError ( "array expected" ) ;
100
103
}
101
104
102
- return createMatcher ( function ( actual ) {
103
- return some ( arrayOfExpectations , function ( expectation ) {
104
- return expectation === actual ;
105
- } ) ;
106
- } , `in(${ valueToString ( arrayOfExpectations ) } )` ) ;
105
+ return createMatcher (
106
+ function ( actual ) {
107
+ return some ( arrayOfExpectations , function ( expectation ) {
108
+ return expectation === actual ;
109
+ } ) ;
110
+ } ,
111
+ `in(${ valueToString ( arrayOfExpectations ) } )` ,
112
+ ) ;
107
113
} ;
108
114
109
115
createMatcher . typeOf = function ( type ) {
@@ -125,12 +131,15 @@ createMatcher.instanceOf = function (type) {
125
131
type ,
126
132
Symbol . hasInstance ,
127
133
"type" ,
128
- "[Symbol.hasInstance]"
134
+ "[Symbol.hasInstance]" ,
129
135
) ;
130
136
}
131
- return createMatcher ( function ( actual ) {
132
- return actual instanceof type ;
133
- } , `instanceOf(${ functionName ( type ) || objectToString ( type ) } )` ) ;
137
+ return createMatcher (
138
+ function ( actual ) {
139
+ return actual instanceof type ;
140
+ } ,
141
+ `instanceOf(${ functionName ( type ) || objectToString ( type ) } )` ,
142
+ ) ;
134
143
} ;
135
144
136
145
/**
@@ -259,111 +268,137 @@ createMatcher.some = function (predicate) {
259
268
createMatcher . array = createMatcher . typeOf ( "array" ) ;
260
269
261
270
createMatcher . array . deepEquals = function ( expectation ) {
262
- return createMatcher ( function ( actual ) {
263
- // Comparing lengths is the fastest way to spot a difference before iterating through every item
264
- var sameLength = actual . length === expectation . length ;
265
- return (
266
- typeOf ( actual ) === "array" &&
267
- sameLength &&
268
- every ( actual , function ( element , index ) {
269
- var expected = expectation [ index ] ;
270
- return typeOf ( expected ) === "array" &&
271
- typeOf ( element ) === "array"
272
- ? createMatcher . array . deepEquals ( expected ) . test ( element )
273
- : deepEqual ( expected , element ) ;
274
- } )
275
- ) ;
276
- } , `deepEquals([${ iterableToString ( expectation ) } ])` ) ;
271
+ return createMatcher (
272
+ function ( actual ) {
273
+ // Comparing lengths is the fastest way to spot a difference before iterating through every item
274
+ var sameLength = actual . length === expectation . length ;
275
+ return (
276
+ typeOf ( actual ) === "array" &&
277
+ sameLength &&
278
+ every ( actual , function ( element , index ) {
279
+ var expected = expectation [ index ] ;
280
+ return typeOf ( expected ) === "array" &&
281
+ typeOf ( element ) === "array"
282
+ ? createMatcher . array . deepEquals ( expected ) . test ( element )
283
+ : deepEqual ( expected , element ) ;
284
+ } )
285
+ ) ;
286
+ } ,
287
+ `deepEquals([${ iterableToString ( expectation ) } ])` ,
288
+ ) ;
277
289
} ;
278
290
279
291
createMatcher . array . startsWith = function ( expectation ) {
280
- return createMatcher ( function ( actual ) {
281
- return (
282
- typeOf ( actual ) === "array" &&
283
- every ( expectation , function ( expectedElement , index ) {
284
- return actual [ index ] === expectedElement ;
285
- } )
286
- ) ;
287
- } , `startsWith([${ iterableToString ( expectation ) } ])` ) ;
292
+ return createMatcher (
293
+ function ( actual ) {
294
+ return (
295
+ typeOf ( actual ) === "array" &&
296
+ every ( expectation , function ( expectedElement , index ) {
297
+ return actual [ index ] === expectedElement ;
298
+ } )
299
+ ) ;
300
+ } ,
301
+ `startsWith([${ iterableToString ( expectation ) } ])` ,
302
+ ) ;
288
303
} ;
289
304
290
305
createMatcher . array . endsWith = function ( expectation ) {
291
- return createMatcher ( function ( actual ) {
292
- // This indicates the index in which we should start matching
293
- var offset = actual . length - expectation . length ;
294
-
295
- return (
296
- typeOf ( actual ) === "array" &&
297
- every ( expectation , function ( expectedElement , index ) {
298
- return actual [ offset + index ] === expectedElement ;
299
- } )
300
- ) ;
301
- } , `endsWith([${ iterableToString ( expectation ) } ])` ) ;
306
+ return createMatcher (
307
+ function ( actual ) {
308
+ // This indicates the index in which we should start matching
309
+ var offset = actual . length - expectation . length ;
310
+
311
+ return (
312
+ typeOf ( actual ) === "array" &&
313
+ every ( expectation , function ( expectedElement , index ) {
314
+ return actual [ offset + index ] === expectedElement ;
315
+ } )
316
+ ) ;
317
+ } ,
318
+ `endsWith([${ iterableToString ( expectation ) } ])` ,
319
+ ) ;
302
320
} ;
303
321
304
322
createMatcher . array . contains = function ( expectation ) {
305
- return createMatcher ( function ( actual ) {
306
- return (
307
- typeOf ( actual ) === "array" &&
308
- every ( expectation , function ( expectedElement ) {
309
- return arrayIndexOf ( actual , expectedElement ) !== - 1 ;
310
- } )
311
- ) ;
312
- } , `contains([${ iterableToString ( expectation ) } ])` ) ;
323
+ return createMatcher (
324
+ function ( actual ) {
325
+ return (
326
+ typeOf ( actual ) === "array" &&
327
+ every ( expectation , function ( expectedElement ) {
328
+ return arrayIndexOf ( actual , expectedElement ) !== - 1 ;
329
+ } )
330
+ ) ;
331
+ } ,
332
+ `contains([${ iterableToString ( expectation ) } ])` ,
333
+ ) ;
313
334
} ;
314
335
315
336
createMatcher . map = createMatcher . typeOf ( "map" ) ;
316
337
317
338
createMatcher . map . deepEquals = function mapDeepEquals ( expectation ) {
318
- return createMatcher ( function ( actual ) {
319
- // Comparing lengths is the fastest way to spot a difference before iterating through every item
320
- var sameLength = actual . size === expectation . size ;
321
- return (
322
- typeOf ( actual ) === "map" &&
323
- sameLength &&
324
- every ( actual , function ( element , key ) {
325
- return expectation . has ( key ) && expectation . get ( key ) === element ;
326
- } )
327
- ) ;
328
- } , `deepEquals(Map[${ iterableToString ( expectation ) } ])` ) ;
339
+ return createMatcher (
340
+ function ( actual ) {
341
+ // Comparing lengths is the fastest way to spot a difference before iterating through every item
342
+ var sameLength = actual . size === expectation . size ;
343
+ return (
344
+ typeOf ( actual ) === "map" &&
345
+ sameLength &&
346
+ every ( actual , function ( element , key ) {
347
+ return (
348
+ expectation . has ( key ) && expectation . get ( key ) === element
349
+ ) ;
350
+ } )
351
+ ) ;
352
+ } ,
353
+ `deepEquals(Map[${ iterableToString ( expectation ) } ])` ,
354
+ ) ;
329
355
} ;
330
356
331
357
createMatcher . map . contains = function mapContains ( expectation ) {
332
- return createMatcher ( function ( actual ) {
333
- return (
334
- typeOf ( actual ) === "map" &&
335
- every ( expectation , function ( element , key ) {
336
- return actual . has ( key ) && actual . get ( key ) === element ;
337
- } )
338
- ) ;
339
- } , `contains(Map[${ iterableToString ( expectation ) } ])` ) ;
358
+ return createMatcher (
359
+ function ( actual ) {
360
+ return (
361
+ typeOf ( actual ) === "map" &&
362
+ every ( expectation , function ( element , key ) {
363
+ return actual . has ( key ) && actual . get ( key ) === element ;
364
+ } )
365
+ ) ;
366
+ } ,
367
+ `contains(Map[${ iterableToString ( expectation ) } ])` ,
368
+ ) ;
340
369
} ;
341
370
342
371
createMatcher . set = createMatcher . typeOf ( "set" ) ;
343
372
344
373
createMatcher . set . deepEquals = function setDeepEquals ( expectation ) {
345
- return createMatcher ( function ( actual ) {
346
- // Comparing lengths is the fastest way to spot a difference before iterating through every item
347
- var sameLength = actual . size === expectation . size ;
348
- return (
349
- typeOf ( actual ) === "set" &&
350
- sameLength &&
351
- every ( actual , function ( element ) {
352
- return expectation . has ( element ) ;
353
- } )
354
- ) ;
355
- } , `deepEquals(Set[${ iterableToString ( expectation ) } ])` ) ;
374
+ return createMatcher (
375
+ function ( actual ) {
376
+ // Comparing lengths is the fastest way to spot a difference before iterating through every item
377
+ var sameLength = actual . size === expectation . size ;
378
+ return (
379
+ typeOf ( actual ) === "set" &&
380
+ sameLength &&
381
+ every ( actual , function ( element ) {
382
+ return expectation . has ( element ) ;
383
+ } )
384
+ ) ;
385
+ } ,
386
+ `deepEquals(Set[${ iterableToString ( expectation ) } ])` ,
387
+ ) ;
356
388
} ;
357
389
358
390
createMatcher . set . contains = function setContains ( expectation ) {
359
- return createMatcher ( function ( actual ) {
360
- return (
361
- typeOf ( actual ) === "set" &&
362
- every ( expectation , function ( element ) {
363
- return actual . has ( element ) ;
364
- } )
365
- ) ;
366
- } , `contains(Set[${ iterableToString ( expectation ) } ])` ) ;
391
+ return createMatcher (
392
+ function ( actual ) {
393
+ return (
394
+ typeOf ( actual ) === "set" &&
395
+ every ( expectation , function ( element ) {
396
+ return actual . has ( element ) ;
397
+ } )
398
+ ) ;
399
+ } ,
400
+ `contains(Set[${ iterableToString ( expectation ) } ])` ,
401
+ ) ;
367
402
} ;
368
403
369
404
createMatcher . bool = createMatcher . typeOf ( "boolean" ) ;
0 commit comments