From 976f32d189278e283064e693de45ea26343e547a Mon Sep 17 00:00:00 2001 From: ka3e Date: Mon, 6 Nov 2017 15:14:51 +0000 Subject: [PATCH] test: refactor addons-napi/test_promise/test.js * remove custom messages for assert that conceal values * add comment explaining test * add block scoping Backport-PR-URL: https://github.com/nodejs/node/pull/19447 PR-URL: https://github.com/nodejs/node/pull/16814 Reviewed-By: Rich Trott Reviewed-By: James M Snell --- test/addons-napi/test_promise/test.js | 31 +++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/test/addons-napi/test_promise/test.js b/test/addons-napi/test_promise/test.js index e0c8a1a7575bdd..b43ecd87363e44 100644 --- a/test/addons-napi/test_promise/test.js +++ b/test/addons-napi/test_promise/test.js @@ -1,8 +1,11 @@ 'use strict'; const common = require('../../common'); -const test_promise = require(`./build/${common.buildType}/test_promise`); + +// This tests the promise-related n-api calls + const assert = require('assert'); +const test_promise = require(`./build/${common.buildType}/test_promise`); // A resolution { @@ -10,8 +13,7 @@ const assert = require('assert'); const promise = test_promise.createPromise(); promise.then( common.mustCall(function(result) { - assert.strictEqual(result, expected_result, - `promise resolved as expected, received ${result}`); + assert.strictEqual(result, expected_result); }), common.mustNotCall()); test_promise.concludeCurrentPromise(expected_result, true); @@ -24,23 +26,24 @@ const assert = require('assert'); promise.then( common.mustNotCall(), common.mustCall(function(result) { - assert.strictEqual(result, expected_result, - `promise rejected as expected, received ${result}`); + assert.strictEqual(result, expected_result); })); test_promise.concludeCurrentPromise(expected_result, false); } // Chaining -const promise = test_promise.createPromise(); -promise.then( - common.mustCall(function(result) { - assert.strictEqual(result, 'chained answer', - 'resolving with a promise chains properly'); - }), - common.mustNotCall()); -test_promise.concludeCurrentPromise(Promise.resolve('chained answer'), true); +{ + const expected_result = 'chained answer'; + const promise = test_promise.createPromise(); + promise.then( + common.mustCall(function(result) { + assert.strictEqual(result, expected_result); + }), + common.mustNotCall()); + test_promise.concludeCurrentPromise(Promise.resolve('chained answer'), true); +} -assert.strictEqual(test_promise.isPromise(promise), true); +assert.strictEqual(test_promise.isPromise(test_promise.createPromise()), true); assert.strictEqual(test_promise.isPromise(Promise.reject(-1)), true); assert.strictEqual(test_promise.isPromise(2.4), false); assert.strictEqual(test_promise.isPromise('I promise!'), false);