-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
t.throws should return the error (or a promise that resolves with the rejection) #493
Comments
Been putting in a little bit of work into this, and I just wanted to get some clarification on the intent before finishing up and posting a PR; test(t => {
const err = t.throws(function () { throw new Error('foo'); });
t.is(err.message, 'foo');
}); test(t => {
const err = await t.throws(function () { return Promise.reject(new Error('foo')); });
t.is(err.message, 'foo');
}); Regardless of what one passes as the second/third argument to I must admit, I'm a little confused by your example - are you expecting a property on the given Error object of I haven't taken #468 into consideration just yet - but I'd like to get cracking on that soon-ish as well. Babysteps. |
@kasperisager does this help? test(t => {
const expected = new Error()
const actual = t.throws(() => { throw expected })
t.is(actual, expected)
}) test(t => {
const expected = new Error()
const actual = t.throws(() => Promise.reject(expected)
t.is(actual, expected)
}) In other words |
Sorry @novemberborn - if your poke was meant for me, I'm afraid you mistyped ever so slightly. Didn't get any notification(s). Regardless, you did make it clearer - tyvm! In my feature branch - In the case of Haven't posted it for review just yet as I know that isn't what the issue description calls for - but if one were to resolve in Sidenote; First attempt(s) at handling this solely in tl;dr; I'm handling rejected promises by returning the result of test(t => {
const expected = 'foo'
const actual = t.throws(() => Promise.reject(new Error(expected))
t.is(actual.message, expected)
}) Not quite there yet I'd say. |
On that note; If we're fine with dropping the properties received from executing |
Q: Do you reckon this behaviour should apply to an Observable as well? I made some changes in my branch to return the full Promise rejection which caused a bunch of failures in test(t => {
const expected = 'foo';
const actual = t.throws(() => new Observable(function (o) { o.error(new Error('foo'); }));
t.is(actual.message, 'foo');
}); |
Too many Kaspers already! 😜 Looking at @jamestalmage's original example again I believe the intent is that if That would imply wrapping the call to You'd need to return No changes should be needed to #468 is related but should not have any bearing on this issue. |
@novemberborn One can never have too many Kaspers! : ) Your suggestion sounds close to what I've done so far. This commit handles the wrapping of This other commit handles Promise bubbling out of I can go ahead and post a |
Yea please open a PR. |
From #492
We could make that recommendation obsolete:
See also: #468 (it also changes the behavior of
t.throws
).The text was updated successfully, but these errors were encountered: