Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[breaking] Don't convert non-Error promise rejection reason #582

Closed
wants to merge 1 commit into from
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: 1 addition & 5 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ x.throws = function (fn, err, msg) {
x.throws(noop, err, msg);
}, function (fnErr) {
x.throws(function () {
if (fnErr instanceof Error) {
throw fnErr;
} else {
throw new Error(fnErr);
}
throw fnErr;
}, err, msg);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the if-guard as well, simply throw fnError. This makes it equivalent to t.throws(() => { throw 'foo' }).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well! I'll go ahead and amend my commit if you don't mind, and save myself the trouble of having to squash later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. It's going to conflict with #576 though 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I'll get on this once #576 is merged.

}
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ Assert that `value` is not deep equal to `expected`.

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

Assert that `function` throws an error or `promise` rejects.
Assert that `function` throws an error, or `promise` rejects with an error.

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

Expand Down
19 changes: 3 additions & 16 deletions test/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,28 +210,15 @@ test('throws with string argument will reject if message does not match', functi
});
});

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 (result) {
t.is(result.passed, true);
t.is(result.result.assertCount, 1);
t.end();
});
});

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

var promise = Promise.reject('abc');
return a.throws(promise, 'abc');
}).run().then(function (result) {
t.is(result.passed, true);
t.is(result.result.assertCount, 1);
t.is(result.passed, false);
t.is(result.reason.name, 'AssertionError');
t.end();
});
});
Expand Down