Skip to content

Commit

Permalink
Fix the .not.rejectedWith tests
Browse files Browse the repository at this point in the history
In Chai `foo.should.not.throw(Constructor, 'string')` would fail only if the error thrown is an instance of `Constructor` **and** if its message includes `'string'`. An instance with a different message would not cause a failure. An instance constructed by something else than `Constructor` would not cause a failure.

.not.rejectedWith's semantics were incompatible with the above.

This commit fixes the test to work according to the correct semantics.
  • Loading branch information
lddubeau authored and domenic committed Sep 27, 2016
1 parent 1f7fc93 commit a8b88d0
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions test/should-promise-specific.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -313,23 +313,13 @@ describe "Promise-specific extensions:", =>
message: "not to be rejected with 'RangeError' but it was rejected with [RangeError: foo bar]"

describe ".not.rejectedWith(RangeError, 'quux')", =>
shouldFail
op: => promise.should.not.be.rejectedWith(RangeError, 'quux')
message: "not to be rejected with 'RangeError' but it was rejected with [RangeError: foo bar]"
shouldPass => promise.should.not.be.rejectedWith(RangeError, 'quux')
describe ".not.rejectedWith(RangeError, /quux/)", =>
shouldFail
op: => promise.should.not.be.rejectedWith(RangeError, /quux/)
message: "not to be rejected with 'RangeError' but it was rejected with [RangeError: foo bar]"

shouldPass => promise.should.not.be.rejectedWith(RangeError, /quux/)
describe ".not.rejectedWith(TypeError, 'foo')", =>
shouldFail
op: => promise.should.not.be.rejectedWith(TypeError, "foo")
message: "not to be rejected with an error including 'foo'"
shouldPass => promise.should.not.be.rejectedWith(TypeError, "foo")
describe ".not.rejectedWith(TypeError, /bar/)", =>
shouldFail
op: => promise.should.not.be.rejectedWith(TypeError, /bar/)
message: "not to be rejected with an error matching /bar/"

shouldPass => promise.should.not.be.rejectedWith(TypeError, /bar/)
describe ".not.rejectedWith(TypeError, 'quux')", =>
shouldPass => promise.should.not.be.rejectedWith(TypeError, "quux")
describe ".not.rejectedWith(TypeError, /quux/)", =>
Expand Down

0 comments on commit a8b88d0

Please sign in to comment.