Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ expect(fn).to.throwException(function (e) { // get the exception object
expect(e).to.be.a(SyntaxError);
});
expect(fn).to.throwException(/matches the exception message/);
expect(fn).to.throwException('exactly matches the exception message');
expect(fn2).to.not.throwException();
```

Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,20 @@
} else {
expect(subject).to.match(fn);
}
} else if ('string' == typeof fn) {
var subject = 'string' == typeof e ? e : e.message;
if (not) {
expect(subject).not.to.equal(fn);
} else {
expect(subject).to.equal(fn);
}
} else if ('function' == typeof fn) {
fn(e);
}
thrown = true;
}

if (isRegExp(fn) && not) {
if ((isRegExp(fn) && not) || ('string' == typeof fn && not)) {
// in the presence of a matcher, ensure the `not` only applies to
// the matching.
this.flags.not = false;
Expand Down
7 changes: 7 additions & 0 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ describe('expect', function () {
expect(itThrowsMessage).to.throwException(/no match/);
}, 'expected \'tobi\' to match /no match/');

expect(itThrowsMessage).to.throwException('tobi');
expect(itThrowsMessage).to.not.throwException('test');

err(function () {
expect(itThrowsMessage).to.throwException('no match');
}, 'expected \'tobi\' to equal \'no match\'');

var subject2;

expect(itThrowsString).to.throwException(function (str) {
Expand Down