From 2cdaad0d71477045f3da6c2e57e62f0db66e7b2c Mon Sep 17 00:00:00 2001 From: Kevin Lanni Date: Sat, 9 Jan 2016 15:31:46 -0700 Subject: [PATCH 1/3] fix how throws method handles rejects --- lib/assert.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/assert.js b/lib/assert.js index afd5991ce..e45deebfc 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.message) { + throw fnErr; + } else { + throw new Error(fnErr); + } }, err, msg); }); } From ba2fb14f44a0b95b290fee6edb8981aecdf795d9 Mon Sep 17 00:00:00 2001 From: Kevin Lanni Date: Sat, 9 Jan 2016 22:20:28 -0700 Subject: [PATCH 2/3] add string reject tests --- test/promise.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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); From 02bf5ac3cca57387c244b577ffec844fe2ec1fc7 Mon Sep 17 00:00:00 2001 From: Kevin Lanni Date: Sun, 10 Jan 2016 13:48:12 -0700 Subject: [PATCH 3/3] use instanceof --- lib/assert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/assert.js b/lib/assert.js index e45deebfc..7190a34b7 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -75,7 +75,7 @@ x.throws = function (fn, err, msg) { x.throws(noop, err, msg); }, function (fnErr) { x.throws(function () { - if (fnErr.message) { + if (fnErr instanceof Error) { throw fnErr; } else { throw new Error(fnErr);