File tree Expand file tree Collapse file tree
lib/node_modules/@stdlib/iter/map/test Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -222,6 +222,32 @@ tape( 'the function returns an iterator protocol-compliant object which invokes
222222 }
223223} ) ;
224224
225+ tape ( 'the function supports specifying the callback execution context' , function test ( t ) {
226+ var ctx ;
227+ var it ;
228+ var r ;
229+ var i ;
230+
231+ ctx = {
232+ 'count' : 0
233+ } ;
234+ it = iterMap ( randu ( ) , scale , ctx ) ;
235+ t . equal ( it . next . length , 0 , 'has zero arity' ) ;
236+
237+ for ( i = 0 ; i < 100 ; i ++ ) {
238+ r = it . next ( ) ;
239+ t . equal ( typeof r . value , 'number' , 'returns a number' ) ;
240+ t . equal ( typeof r . done , 'boolean' , 'returns a boolean' ) ;
241+ }
242+ t . equal ( ctx . count , 100 , 'returns expected value' ) ;
243+ t . end ( ) ;
244+
245+ function scale ( v , i ) {
246+ this . count += 1 ; // eslint-disable-line no-invalid-this
247+ return v * ( i + 1 ) ;
248+ }
249+ } ) ;
250+
225251tape ( 'the returned iterator has a `return` method for closing an iterator (no argument)' , function test ( t ) {
226252 var it ;
227253 var r ;
You can’t perform that action at this time.
0 commit comments