Skip to content

Commit 5e02387

Browse files
kasperlewausindresorhus
authored andcommitted
Close #582 PR: [breaking] Don't convert non-Error promise rejection reason. Fixes #468
1 parent db4658d commit 5e02387

File tree

3 files changed

+5
-22
lines changed

3 files changed

+5
-22
lines changed

lib/assert.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ x.throws = function (fn, err, msg) {
7979
x.throws(noop, err, msg);
8080
}, function (fnErr) {
8181
x.throws(function () {
82-
if (fnErr instanceof Error) {
83-
throw fnErr;
84-
} else {
85-
throw new Error(fnErr);
86-
}
82+
throw fnErr;
8783
}, err, msg);
8884
});
8985
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ Assert that `value` is not deep equal to `expected`.
562562

563563
### .throws(function|promise, [error, [message]])
564564

565-
Assert that `function` throws an error or `promise` rejects.
565+
Assert that `function` throws an error, or `promise` rejects with an error.
566566

567567
`error` can be a constructor, regex, error message or validation function.
568568

test/promise.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,28 +210,15 @@ test('throws with string argument will reject if message does not match', functi
210210
});
211211
});
212212

213-
test('handle throws with regex with string reject', function (t) {
214-
ava(function (a) {
215-
a.plan(1);
216-
217-
var promise = Promise.reject('abc');
218-
return a.throws(promise, /abc/);
219-
}).run().then(function (result) {
220-
t.is(result.passed, true);
221-
t.is(result.result.assertCount, 1);
222-
t.end();
223-
});
224-
});
225-
226-
test('handle throws with string with string reject', function (t) {
213+
test('does not handle throws with string reject', function (t) {
227214
ava(function (a) {
228215
a.plan(1);
229216

230217
var promise = Promise.reject('abc');
231218
return a.throws(promise, 'abc');
232219
}).run().then(function (result) {
233-
t.is(result.passed, true);
234-
t.is(result.result.assertCount, 1);
220+
t.is(result.passed, false);
221+
t.is(result.reason.name, 'AssertionError');
235222
t.end();
236223
});
237224
});

0 commit comments

Comments
 (0)