New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert.throws() should return thrown error #185

Closed
nonplus opened this Issue Jul 9, 2013 · 0 comments

Comments

Projects
None yet
1 participant
@nonplus

nonplus commented Jul 9, 2013

It would be convenient if the return value of assert.throws() were the thrown error. This would allow you to do additional assertion on the return error; e.g. verifying that its code property has a specific value:

var err = assert.throws(function() { myFunction("bogus param"); },
    /Invalid parameters/);
assert.equal(err.code, "ExpectedCode", "err.code");

Alternatively, you could add support for passing a validation function as the matcher:

assert.throws(function() { myFunction("bogus param"); },
    function(err) {
        assert.match(err.message, /Invalid parameters/, "err.message");
        assert.equal(err.code, "ExpectedCode", "err.code");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment