assert.throws() should return thrown error #185

nonplus opened this Issue Jul 9, 2013 · 0 comments


None yet

1 participant

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