Permalink
Browse files

Providing useful feedback when using t.throws() with async functions

  • Loading branch information...
grant37 authored and novemberborn committed Sep 30, 2018
1 parent 71eede7 commit f125b4df36ea0e6c552b9ac61278a8fa93521a6e
Showing with 20 additions and 0 deletions.
  1. +11 −0 lib/assert.js
  2. +9 −0 test/assert.js
View
@@ -332,6 +332,17 @@ function wrapAssertions(callbacks) {
let threw = false;
try {
retval = fn();
if (isPromise(retval)) {
try {
retval.catch(noop);
} catch (_) {}
fail(this, new AssertionError({
assertion: 'throws',
message,
values: [formatWithLabel('Function returned a promise. Use `t.throwsAsync()` instead:', retval)]
}));
return;
}
} catch (error) {
actual = error;
threw = true;
View
@@ -713,6 +713,15 @@ test('.throws()', gather(t => {
values: [{label: 'Function returned:', formatted: /undefined/}]
});
// Fails because the function returned a promise.
failsWith(t, () => {
assertions.throws(() => Promise.resolve());
}, {
assertion: 'throws',
message: '',
values: [{label: 'Function returned a promise. Use `t.throwsAsync()` instead:', formatted: /Promise/}]
});
// Fails because thrown exception is not an error
failsWith(t, () => {
assertions.throws(() => {

0 comments on commit f125b4d

Please sign in to comment.