From 4917d8cfef828b77bdd8f15cb4cdb7f5ee6babb3 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' Backport-PR-URL: https://github.com/nodejs/node/pull/15479 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 a0eb8d7a4a..b742e69d7f 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]]])