Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ x.throws = function (fn, err, msg) {
x.throws(noop, err, msg);
}, function (fnErr) {
x.throws(function () {
throw fnErr;
if (fnErr instanceof Error) {
throw fnErr;
} else {
throw new Error(fnErr);
}
}, err, msg);
});
}
Expand Down
24 changes: 24 additions & 0 deletions test/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,30 @@ test('handle throws with string', function (t) {
});
});

test('handle throws with regex with string reject', function (t) {
ava(function (a) {
a.plan(1);

var promise = Promise.reject('abc');
return a.throws(promise, /abc/);
}).run().then(function (a) {
t.notOk(a.assertionError);
t.end();
});
});

test('handle throws with string with string reject', function (t) {
ava(function (a) {
a.plan(1);

var promise = Promise.reject('abc');
return a.throws(promise, 'abc');
}).run().then(function (a) {
t.notOk(a.assertionError);
t.end();
});
});

test('handle throws with false-positive promise', function (t) {
ava(function (a) {
a.plan(1);
Expand Down