From 99d4a67c9847eeb22e83ccabddcb4638d4e37d64 Mon Sep 17 00:00:00 2001 From: Kinnan Kwok Date: Fri, 6 Oct 2017 11:43:43 -0700 Subject: [PATCH] test: add results to assertion messages --- test/addons-napi/test_promise/test.js | 85 ++++++++++++++++----------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/test/addons-napi/test_promise/test.js b/test/addons-napi/test_promise/test.js index 4c2a2e5e76c9fb..499358eb0dde04 100644 --- a/test/addons-napi/test_promise/test.js +++ b/test/addons-napi/test_promise/test.js @@ -4,29 +4,33 @@ const common = require('../../common'); const test_promise = require(`./build/${common.buildType}/test_promise`); const assert = require('assert'); -let expected_result, promise; +let promise; // A resolution -expected_result = 42; -promise = test_promise.createPromise(); -promise.then( - common.mustCall(function(result) { - assert.strictEqual(result, expected_result, - 'promise resolved as expected'); - }), - common.mustNotCall()); -test_promise.concludeCurrentPromise(expected_result, true); +{ + let expected_result = 42; + promise = test_promise.createPromise(); + promise.then( + common.mustCall(function(result) { + assert.strictEqual(result, expected_result, + `promise resolved as expected, received ${result}`); + }), + common.mustNotCall()); + test_promise.concludeCurrentPromise(expected_result, true); +} // A rejection -expected_result = 'It\'s not you, it\'s me.'; -promise = test_promise.createPromise(); -promise.then( - common.mustNotCall(), - common.mustCall(function(result) { - assert.strictEqual(result, expected_result, - 'promise rejected as expected'); - })); -test_promise.concludeCurrentPromise(expected_result, false); +{ + let expected_result = 'It\'s not you, it\'s me.'; + promise = test_promise.createPromise(); + promise.then( + common.mustNotCall(), + common.mustCall(function(result) { + assert.strictEqual(result, expected_result, + `promise rejected as expected, received ${result}`); + })); + test_promise.concludeCurrentPromise(expected_result, false); +} // Chaining promise = test_promise.createPromise(); @@ -38,23 +42,38 @@ promise.then( common.mustNotCall()); test_promise.concludeCurrentPromise(Promise.resolve('chained answer'), true); -assert.strictEqual(test_promise.isPromise(promise), true, - 'natively created promise is recognized as a promise'); +let result; +result = test_promise.isPromise(promise); +assert.strictEqual(result, true, + 'natively created promise is recognized as a promise' + + `, received ${result}`); -assert.strictEqual(test_promise.isPromise(Promise.reject(-1)), true, - 'Promise created with JS is recognized as a promise'); +result = test_promise.isPromise(Promise.reject(-1)); +assert.strictEqual(result, true, + 'Promise created with JS is recognized as a promise' + + `, received ${result}`); -assert.strictEqual(test_promise.isPromise(2.4), false, - 'Number is recognized as not a promise'); +result = test_promise.isPromise(2.4); +assert.strictEqual(result, false, + 'Number is recognized as not a promise' + + `, received ${result}`); -assert.strictEqual(test_promise.isPromise('I promise!'), false, - 'String is recognized as not a promise'); +result = test_promise.isPromise('I promise!'); +assert.strictEqual(result, false, + 'String is recognized as not a promise' + + `, received ${result}`); -assert.strictEqual(test_promise.isPromise(undefined), false, - 'undefined is recognized as not a promise'); +result = test_promise.isPromise(undefined); +assert.strictEqual(result, false, + 'undefined is recognized as not a promise' + + `, received ${result}`); -assert.strictEqual(test_promise.isPromise(null), false, - 'null is recognized as not a promise'); +result = test_promise.isPromise(null); +assert.strictEqual(result, false, + 'null is recognized as not a promise' + + `, received ${result}`); -assert.strictEqual(test_promise.isPromise({}), false, - 'an object is recognized as not a promise'); +result = test_promise.isPromise({}); +assert.strictEqual(result, false, + 'an object is recognized as not a promise' + + `, received ${result}`);