Skip to content

Commit 2b3b2d3

Browse files
committed
test: add setTimeout/setInterval multi-arg tests
It turns out we have little to no test coverage for setTimeout() and setInterval() calls with optional arguments. Now we do. PR-URL: #1221 Reviewed-By: Trevor Norris <[email protected]>
1 parent 33fea6e commit 2b3b2d3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/parallel/test-timers-args.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var common = require('../common');
2+
var assert = require('assert');
3+
4+
function range(n) {
5+
return 'x'.repeat(n + 1).split('').map(function(_, i) { return i; });
6+
}
7+
8+
function timeout(nargs) {
9+
var args = range(nargs);
10+
setTimeout.apply(null, [callback, 1].concat(args));
11+
12+
function callback() {
13+
assert.deepEqual([].slice.call(arguments), args);
14+
if (nargs < 128) timeout(nargs + 1);
15+
}
16+
}
17+
18+
function interval(nargs) {
19+
var args = range(nargs);
20+
var timer = setTimeout.apply(null, [callback, 1].concat(args));
21+
22+
function callback() {
23+
clearInterval(timer);
24+
assert.deepEqual([].slice.call(arguments), args);
25+
if (nargs < 128) interval(nargs + 1);
26+
}
27+
}
28+
29+
timeout(0);
30+
interval(0);

0 commit comments

Comments
 (0)