From 0d3ef5b0f863a1caa538673c08747d62d23f3d31 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 5 Aug 2017 18:41:10 -0700 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/14645 Reviewed-By: Luigi Pinca Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Refael Ackermann --- test/parallel/test-next-tick.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/parallel/test-next-tick.js b/test/parallel/test-next-tick.js index 9c69efeb784d64..511d0559cd1e94 100644 --- a/test/parallel/test-next-tick.js +++ b/test/parallel/test-next-tick.js @@ -21,6 +21,7 @@ 'use strict'; const common = require('../common'); + const assert = require('assert'); process.nextTick(common.mustCall(function() { @@ -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()); });