Skip to content

assert: inconsistency in assert.doesNotThrow #2385

Closed
@jasnell

Description

@jasnell

nodejs/node-v0.x-archive#6470 is an old PR that never landed but points to a valid issue.

The test case:

var assert = require('assert');
assert.doesNotThrow(function() {
  throw new Error();
});

Prints the error stack but does not output an AssertionError.

However,

var assert = require('assert');
assert.doesNotThrow(function() {
  throw new Error();
}, Error);

Raises an Assertion Error (AssertionError: Got unwanted exception (Error)..

var assert = require('assert');
assert.doesNotThrow(function() {
  throw 'custom message';
});

And

var assert = require('assert');
assert.doesNotThrow(function() {
  throw 'custom message';
}, 'custom message');

Both just output custom message without raising the Assertion Error.

The solution submitted in nodejs/node-v0.x-archive#6470 should be investigated as a possible fix but possibly needs to be revisited.

Metadata

Metadata

Assignees

No one assigned

    Labels

    assertIssues and PRs related to the assert subsystem.docIssues and PRs related to the documentations.good first issueIssues that are suitable for first-time contributors.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions