Closed
Description
From #492
test(t => { t.plan(2); return shouldRejectWithFoo().catch(reason => { t.is(reason.message, 'HelloMessage') // Prefer t.throws if all you care about is the message t.is(reason.foo, 'bar'); }); }); test(t => { t.plan(2); try { shouldThrow(); } catch (err) { t.is(err.message, 'HelloMessage') // Prefer t.throws if all you care about is the message t.is(err.foo, 'bar'); } });In most cases, you should prefer the
t.throws()
assertion, but this is an acceptable use sincet.throws()
only allows you to assert against the error'smessage
property.
We could make that recommendation obsolete:
test(async t => {
var err = await t.throws(shouldRejectWithFoo, 'HelloMessage');
t.is(err.foo, 'bar');
});
test(t => {
var err = t.throws(shouldThrow, 'HelloMessage');
t.is(err.foo, 'bar');
});
See also: #468 (it also changes the behavior of t.throws
).
Metadata
Metadata
Assignees
Labels
No labels