Skip to content

t.doesNotThrow() expected parameters seems to be ignored #553

Open
@m-r-r

Description

@m-r-r

Hello,

I read the code of the method t.doesNotThrow() and I don't understand the purpose of the expected parameter.

The documentation says :

expected, if present, limits what should not be thrown, and must be a RegExp or Function. The RegExp matches the string representation of the exception, as generated by err.toString(). For example, if you set expected to /user/, the test will fail only if the string representation of the exception contains the word user. Any other exception will result in a passed test. The Function is the exception thrown (e.g. Error).

So, if my understanding is correct, the following tests should not fail :

const test = require("tape");

test('should not fail', (t) => {
    t.doesNotThrow(
        () => { throw new Error("Foo bar") },
        TypeError,
        "the callback does not throw a TypeError"
    );
    t.end();
});

test('should not fail', (t) => {
    t.doesNotThrow(
        () => { throw new Error("Foo bar") },
        /baz/,
        "the callback does not throw 'baz'"
    );
    t.end();
});

But the current behavior of t.doesNotThrow() is to always fail if the callback throws an exception.

Should the method t.doesNotThrow() be updated to match the documentation, or is my understanding of the documentation incorrect ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions