33const metasync = require ( '..' ) ;
44const metatests = require ( 'metatests' ) ;
55
6+ const arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] ;
7+
68metatests . test ( 'find with error' , test => {
79 const data = [ 1 , 2 , 3 ] ;
810 const expectedErrorMessage = 'Intentional error' ;
@@ -23,12 +25,11 @@ metatests.test('find with error', test => {
2325} ) ;
2426
2527metatests . test ( 'find' , test => {
26- const data = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] ;
2728 const expected = 15 ;
2829 const predicate = ( item , callback ) =>
2930 process . nextTick ( ( ) => callback ( null , item % 3 === 0 && item % 5 === 0 ) ) ;
3031
31- metasync . find ( data , predicate , ( err , result ) => {
32+ metasync . find ( arr , predicate , ( err , result ) => {
3233 test . error ( err , 'must not return an error' ) ;
3334 test . strictSame ( result , expected , `result should be: ${ expected } ` ) ;
3435 test . end ( ) ;
@@ -48,9 +49,8 @@ metatests.test('with empty array', test => {
4849} ) ;
4950
5051metatests . test ( 'with array without element which is searching' , test => {
51- const data = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] ;
5252 metasync . find (
53- data ,
53+ arr ,
5454 ( el , callback ) => process . nextTick ( ( ) => callback ( null , el === 20 ) ) ,
5555 ( err , result ) => {
5656 test . error ( err ) ;
@@ -59,3 +59,16 @@ metatests.test('with array without element which is searching', test => {
5959 }
6060 ) ;
6161} ) ;
62+
63+ metatests . test ( 'find with another iterable' , test => {
64+ const map = new Map ( [ [ 1 , 'a' ] , [ 2 , 'b' ] , [ 3 , 'c' ] ] ) ;
65+ const expected = [ 3 , 'c' ] ;
66+ const predicate = ( item , callback ) =>
67+ process . nextTick ( ( ) => callback ( null , item [ 1 ] === 'c' ) ) ;
68+
69+ metasync . find ( map , predicate , ( err , result ) => {
70+ test . error ( err ) ;
71+ test . strictSame ( result , expected ) ;
72+ test . end ( ) ;
73+ } ) ;
74+ } ) ;
0 commit comments