diff --git a/lib/assert.js b/lib/assert.js index afd5991ce..7190a34b7 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -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); }); } diff --git a/test/promise.js b/test/promise.js index 9fe4e34fd..51a758eb2 100644 --- a/test/promise.js +++ b/test/promise.js @@ -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);