Skip to content

Commit

Permalink
assert: fix strict regression
Browse files Browse the repository at this point in the history
Using `assert()` or `assert.ok()` resulted in a error since a
refactoring.

Refs: #17582

Backport-PR-URL: #23223
PR-URL: #17903
Refs: #17582
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
BridgeAR authored and MylesBorins committed Oct 31, 2018
1 parent f2af930 commit 562787e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,15 @@ assert.ifError = function ifError(err) { if (err) throw err; };

// Expose a strict only variant of assert
function strict(value, message) {
if (!value) innerFail(value, true, message, '==', strict);
if (!value) {
innerFail({
actual: value,
expected: true,
message,
operator: '==',
stackStartFn: strict
});
}
}
assert.strict = Object.assign(strict, assert, {
equal: assert.strictEqual,
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,14 @@ common.expectsError(
assert.equal(Object.keys(assert).length, Object.keys(a).length);
/* eslint-enable no-restricted-properties */
assert(7);
common.expectsError(
() => assert(),
{
code: 'ERR_ASSERTION',
type: assert.AssertionError,
message: 'undefined == true'
}
);
}

common.expectsError(
Expand Down

0 comments on commit 562787e

Please sign in to comment.