You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this works as expected (passes when there is a cookie, fails otherwise): expect(response).to.be.loggedIn;
But when negated, it still always checks for the cookie existence, ie. expect(response).to.not.be.loggedIn;
still fails when the cookie is missing, passes when it's present
The assertion from custom property used directly works both normally and negated as expected: expect(response).to.have.cookie('session'); expect(response).to.not.have.cookie('session');
The text was updated successfully, but these errors were encountered:
I'm somewhat new to Chai but it looks like an anti-pattern to me. It seems to me the pattern you're following is creating a new assertion with the same object. Instead it should be using the assertion the function was called for. It should be as simple as changing expect(response) in your function to this.
Here's an example to demonstrate.
function loggedInBroken(response) {
expect(response).to.have.cookie('loggedIn', 'yes');
}
function loggedInWorking() {
this.to.have.cookie('loggedIn', 'yes');
}
describe('Chakram plugins', function () {
var withGoodCookie = chakram.get('http://httpbin.org/cookies/set?loggedIn=yes');
var withBadCookie = chakram.get('http://httpbin.org/cookies/set?loggedIn=no');
var withNoCookie = chakram.get('http://httpbin.org/get');
it('should work with loggedInWorking', function () {
chakram.addProperty('loggedIn', loggedInWorking);
expect(withGoodCookie).to.be.loggedIn;
expect(withBadCookie).to.not.be.loggedIn;
expect(withNoCookie).to.not.be.loggedIn;
return chakram.wait();
});
it('should work with loggedInBroken', function () {
chakram.addProperty('loggedIn', loggedInBroken);
expect(withGoodCookie).to.be.loggedIn;
expect(withBadCookie).to.not.be.loggedIn; // nope
expect(withNoCookie).to.not.be.loggedIn; // nope
return chakram.wait();
});
});
Note that you will run into similar issues with other plugins such as json for the very same reasons.
An example:
Let
loggedIn
be defined as follows:this works as expected (passes when there is a cookie, fails otherwise):
expect(response).to.be.loggedIn;
But when negated, it still always checks for the cookie existence, ie.
expect(response).to.not.be.loggedIn;
still fails when the cookie is missing, passes when it's present
The assertion from custom property used directly works both normally and negated as expected:
expect(response).to.have.cookie('session');
expect(response).to.not.have.cookie('session');
The text was updated successfully, but these errors were encountered: