Skip to content

Commit c77db9a

Browse files
committed
Add execution context test
1 parent 802f57f commit c77db9a

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

  • lib/node_modules/@stdlib/iter/map/test

lib/node_modules/@stdlib/iter/map/test/test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
225251
tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) {
226252
var it;
227253
var r;

0 commit comments

Comments
 (0)