Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add results to assertion messages #16024

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 52 additions & 33 deletions test/addons-napi/test_promise/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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}`);