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

Fix assertions on functions that throw primitives #133

Merged
merged 1 commit into from
Jan 28, 2013
Merged

Fix assertions on functions that throw primitives #133

merged 1 commit into from
Jan 28, 2013

Conversation

RubenVerborgh
Copy link
Contributor

Although not recommended, JavaScript functions can throw anything, i.e., not necessarily an Error.

However, Chai does not nicely deal with them. Consider the following snippet of code:

(function () { throw "test"; }).should.throw("test");
(function () { throw "test"; }).should.throw("whatever");
(function () { throw "test"; }).should.not.throw("whatever");

Currently, line 2 incorrectly doesn't cause an error, but line 3 does:

expected [Function] to not throw an error but 'test' was thrown

This pull request adds support for primitive errors, correctly resulting in this error for line 2:

expected [Function] to throw error including 'whatever' but got 'test'

logicalparadox added a commit that referenced this pull request Jan 28, 2013
Fix assertions on functions that throw primitives
@logicalparadox logicalparadox merged commit 02ed69e into chaijs:master Jan 28, 2013
@RubenVerborgh RubenVerborgh deleted the throw branch January 28, 2013 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants