From e4e98ba7e8ff3118973a1f9516fe16c0c7b8e19a Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 9 Apr 2017 10:36:14 -0700 Subject: [PATCH 1/3] assert: improve assert.fail() API assert.fail() has two possible function signatures, both of which are not intuitive. It virtually guarantees that people who try to use assert.fail() without carefully reading the docs will end up using it incorrectly. This change maintains backwards compatibility with the two valid uses (arguments 1 2 and 4 supplied but argument 3 falsy, and argument 3 supplied but arguments 1 2 and 4 all falsy) but also adds the far more intuitive first-argument-only and first-two-arguments-only possibilities. assert.fail('boom'); // AssertionError: boom assert.fail('a', 'b'); // AssertionError: 'a' != 'b' --- doc/api/assert.md | 9 ++++++++- lib/assert.js | 4 ++++ test/parallel/test-assert-fail.js | 33 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-assert-fail.js diff --git a/doc/api/assert.md b/doc/api/assert.md index 925108b8fcf028..58c3e7c07f04a9 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -256,6 +256,7 @@ If the values are not equal, an `AssertionError` is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error message is assigned. +## assert.fail(message) ## assert.fail(actual, expected, message, operator)