You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Change the following test in test/throws.js as below:
function fn() {
throw new TypeError('RegExp');
}
test('throws (RegExp match)', function (t) {
t.throws(fn, /^RegExp$/);
t.end();
});
This will fail, as the match is against the stringified TypeError, not just the message, as outlined here.
The TAP output fails with:
not ok test/throws.js ................................... 2/4
Command: "/usr/local/bin/node throws.js"
TAP version 13
ok 1 should throw
not ok 2 should throw
---
operator: throws
expected:
"'/^RegExp$/'":
actual:
"{ [TypeError": |
RegExp] message: 'RegExp' }
...
ok 3 should throw
not ok 4 test/throws.js
---
exit: 1
command: "/usr/local/bin/node throws.js"
...
The actual parameter, if we look in lib/test.js, is the raw Error object, but in the case of a RegExp match, I think it should be the stringified error.
Making the obvious change (making actual be String(caught && caught.error) in this case doesn't seem to work:
not ok test/throws.js ................................... 2/4
Command: "/usr/local/bin/node throws.js"
TAP version 13
ok 1 should throw
not ok 2 should throw
---
operator: throws
expected:
"'/^RegExp$/'":
actual:
"'TypeError": RegExp'
...
ok 3 should throw
not ok 4 test/throws.js
---
exit: 1
command: "/usr/local/bin/node throws.js"
...
since the quotes aren't balanced. However, the test passes with:
@yangmillstheory.test stringifies its value, so it is already the stringified error :-) I added some tests to close #269 that illustrate how it works.
As for the unbalanced quotes - I think that's something specific to your machine - the output in your second code block has some weirdness too. What OS and node version are you running?
I'm going to close this for now, but we can reopen if there's something we need to do here.
Change the following test in
test/throws.js
as below:This will fail, as the match is against the stringified
TypeError
, not just the message, as outlined here.The TAP output fails with:
The
actual
parameter, if we look inlib/test.js
, is the rawError
object, but in the case of aRegExp
match, I think it should be the stringified error.Making the obvious change (making
actual
beString(caught && caught.error)
in this case doesn't seem to work:since the quotes aren't balanced. However, the test passes with:
I think the
actual
output should be the stringified error, which is an easy enough change, but why are the quotes unbalanced?The text was updated successfully, but these errors were encountered: