@@ -234,6 +234,46 @@ describe('Collection API', function() {
234
234
} ) ;
235
235
} ) ;
236
236
237
+ describe ( 'some' , function ( ) {
238
+ it ( 'lets you test each element of a collection and stops when one passes the test' , function ( ) {
239
+ const each = jest . genMockFunction ( ) . mockImplementation ( ( ) => true ) ;
240
+ Collection . fromNodes ( nodes ) . some ( each ) ;
241
+
242
+ expect ( each . mock . calls . length ) . toBe ( 1 ) ;
243
+ expect ( each . mock . calls [ 0 ] [ 0 ] . value ) . toBe ( nodes [ 0 ] ) ;
244
+ } ) ;
245
+
246
+ it ( 'returns true if at least one element passes the test' , function ( ) {
247
+ const result = Collection . fromNodes ( nodes ) . some ( ( _ , i ) => i === 1 ) ;
248
+ expect ( result ) . toBe ( true ) ;
249
+ } ) ;
250
+
251
+ it ( 'returns false if no elements pass the test' , function ( ) {
252
+ const result = Collection . fromNodes ( nodes ) . some ( ( ) => false ) ;
253
+ expect ( result ) . toBe ( false ) ;
254
+ } ) ;
255
+ } ) ;
256
+
257
+ describe ( 'every' , function ( ) {
258
+ it ( 'lets you test each element of a collection and stops when one fails the test' , function ( ) {
259
+ const each = jest . genMockFunction ( ) . mockImplementation ( ( ) => false ) ;
260
+ Collection . fromNodes ( nodes ) . every ( each ) ;
261
+
262
+ expect ( each . mock . calls . length ) . toBe ( 1 ) ;
263
+ expect ( each . mock . calls [ 0 ] [ 0 ] . value ) . toBe ( nodes [ 0 ] ) ;
264
+ } ) ;
265
+
266
+ it ( 'returns true if all elements pass the test' , function ( ) {
267
+ const result = Collection . fromNodes ( nodes ) . every ( ( ) => true ) ;
268
+ expect ( result ) . toBe ( true ) ;
269
+ } ) ;
270
+
271
+ it ( 'returns false if at least one element does not pass the test' , function ( ) {
272
+ const result = Collection . fromNodes ( nodes ) . every ( ( _ , i ) => i === 1 ) ;
273
+ expect ( result ) . toBe ( false ) ;
274
+ } ) ;
275
+ } ) ;
276
+
237
277
describe ( 'map' , function ( ) {
238
278
it ( 'returns a new collection with mapped values' , function ( ) {
239
279
const root = Collection . fromNodes ( nodes ) ;
0 commit comments