From d25b8de37c478bcf8d5df8912c7bc4e6c8e666bc Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 9 Apr 2017 10:36:14 -0700 Subject: [PATCH 1/4] assert: improve assert.fail() API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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' PR-URL: https://github.com/nodejs/node/pull/12293 Reviewed-By: Anna Henningsen Reviewed-By: Michaël Zasso Reviewed-By: James M Snell --- doc/api/assert.md | 9 ++++++++- lib/assert.js | 4 ++++ test/parallel/test-assert-fail.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/doc/api/assert.md b/doc/api/assert.md index a0eb8d7a4a188e..b742e69d7fb312 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -194,6 +194,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[, stackStartFunction]]])