-
Notifications
You must be signed in to change notification settings - Fork 112
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
rejectedWith false positives when passed undefined #123
Comments
Unfortunately I'm finding this issue is true with any undefined condition, all these test pass just fine return Promise.reject('rejected').should.be.fullfilled |
return Promise.reject(2).should.be.rejectedWith(1);
return Promise.resolve().should.be.rejectedWith(1); EDIT On further investigation, I've realised that the false-positive issue is a lot more widespread than initially thought. return Promise.reject(false).should.be.rejectedWith(true); // passes I'm trying to fix this in my own fork, hopefully to open a PR. However, I don't understand the logic behind some of the assertions/expectations. For example, the following is a PASS, and there is a test for it, to ensure it stays that way. return Promise.reject('a long error string').should.be.rejectedWith('error'); // passes I'd expect the above to fail. If I wanted to test partial strings, I'd use a regex, like so: return Promise.reject('a long error string').should.be.rejectedWith(/error/); Can anyone explain? |
I wonder if this is connected to #126.
Chai matches error strings based on substring matching, so we do the same in Chai as Promised. |
The best fix for this and many other issues would be that described in #47 (comment)... |
Some early work for this has been done in chaijs/chai#470 but it needs some work to get it to a useful point. PRs welcome 😄 |
After stumbling upon this issue, it seems like the problem is just with return expect(somePromise).to.be.rejected.and.to.eventually.equal(new Error('some error message')); ...it works just fine. |
it also fails to behave correctly with empty strings and single characters: |
I guess this is a dupe of #56. |
If I pass
undefined
torejectedWith()
I get a dangerous false-positive test.For example:
If I fat-finger
Errors.SomeError
, to something likeErrors.SomeErrro
, it will be undefined, and the expectation passes, when it shouldn't. This is gives the potential for false-positives which I feel are very dangerous.Are there any better ways of dealing with this?
The text was updated successfully, but these errors were encountered: