Skip to content

Commit

Permalink
test: check this value for nextTick()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Trott committed Aug 10, 2017
1 parent 2249234 commit 0d3ef5b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/parallel/test-next-tick.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

'use strict';
const common = require('../common');

const assert = require('assert');

process.nextTick(common.mustCall(function() {
Expand All @@ -40,8 +41,23 @@ const obj = {};
process.nextTick(function(a, b) {
assert.strictEqual(a, 42);
assert.strictEqual(b, obj);
assert.strictEqual(this, undefined);
}, 42, obj);

process.nextTick((a, b) => {
assert.strictEqual(a, 42);
assert.strictEqual(b, obj);
assert.deepStrictEqual(this, {});
}, 42, obj);

process.nextTick(function() {
assert.strictEqual(this, null);
}, 1, 2, 3, 4);

process.nextTick(() => {
assert.deepStrictEqual(this, {});
}, 1, 2, 3, 4);

process.on('exit', function() {
process.nextTick(common.mustNotCall());
});

0 comments on commit 0d3ef5b

Please sign in to comment.