Skip to content

Commit 0d3ef5b

Browse files
committed
test: check this value for nextTick()
Depending on how many arguments are provided, `nextTick()` may run its callback with `this` set to `null` or not. Add assertions for both cases. PR-URL: #14645 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 2249234 commit 0d3ef5b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/parallel/test-next-tick.js

+16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
'use strict';
2323
const common = require('../common');
24+
2425
const assert = require('assert');
2526

2627
process.nextTick(common.mustCall(function() {
@@ -40,8 +41,23 @@ const obj = {};
4041
process.nextTick(function(a, b) {
4142
assert.strictEqual(a, 42);
4243
assert.strictEqual(b, obj);
44+
assert.strictEqual(this, undefined);
4345
}, 42, obj);
4446

47+
process.nextTick((a, b) => {
48+
assert.strictEqual(a, 42);
49+
assert.strictEqual(b, obj);
50+
assert.deepStrictEqual(this, {});
51+
}, 42, obj);
52+
53+
process.nextTick(function() {
54+
assert.strictEqual(this, null);
55+
}, 1, 2, 3, 4);
56+
57+
process.nextTick(() => {
58+
assert.deepStrictEqual(this, {});
59+
}, 1, 2, 3, 4);
60+
4561
process.on('exit', function() {
4662
process.nextTick(common.mustNotCall());
4763
});

0 commit comments

Comments
 (0)