Skip to content

Commit eea8752

Browse files
therealklannisindresorhus
authored andcommitted
Close #414 PR: Fix t.throws/doesNotThrow not outputting failure reason.
1 parent 8e0a6e9 commit eea8752

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/assert.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ x.throws = function (fn, err, msg) {
7575
x.throws(noop, err, msg);
7676
}, function (fnErr) {
7777
x.throws(function () {
78-
throw fnErr;
78+
if (fnErr instanceof Error) {
79+
throw fnErr;
80+
} else {
81+
throw new Error(fnErr);
82+
}
7983
}, err, msg);
8084
});
8185
}

test/promise.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,30 @@ test('handle throws with string', function (t) {
177177
});
178178
});
179179

180+
test('handle throws with regex with string reject', function (t) {
181+
ava(function (a) {
182+
a.plan(1);
183+
184+
var promise = Promise.reject('abc');
185+
return a.throws(promise, /abc/);
186+
}).run().then(function (a) {
187+
t.notOk(a.assertionError);
188+
t.end();
189+
});
190+
});
191+
192+
test('handle throws with string with string reject', function (t) {
193+
ava(function (a) {
194+
a.plan(1);
195+
196+
var promise = Promise.reject('abc');
197+
return a.throws(promise, 'abc');
198+
}).run().then(function (a) {
199+
t.notOk(a.assertionError);
200+
t.end();
201+
});
202+
});
203+
180204
test('handle throws with false-positive promise', function (t) {
181205
ava(function (a) {
182206
a.plan(1);

0 commit comments

Comments
 (0)