From 758b8b6e5d1aa171827759e51847bcc4f2eea7a3 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 9 Apr 2017 10:36:14 -0700 Subject: [PATCH] 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 | 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 925108b8fc..58c3e7c07f 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)