Simply speaking, actual result is
expect(null).to.be.null; // ok
expect(null).not.to.be.not.null; // Error: expected null not to be null
While from logical point of view, I would expect ¬¬p ⇔ p
Above example may look un-practical and obscure, but that's the same reason why it hit's in regular use of
chai.Assertion.addProperty('foo', function(){
...
utils.transferFlags(this, newAssert, false);
newAssert.not.null;
});
expect(bar).not.to.be.foo;
what makes transferring negation flag quite tricky.
Forgive me if I'm doing something dumb, I'm quite new to creating own assertions.
@tomalec One thing you could do is unset an existing negated flag from within your custom assertion:
utils.flag(this, 'negate', false);
Having two not flags cancel each other out is problematic in some situations, such as:
expect(42).to.not.equal(41).and.not.equal(43);
The typical counterargument to this is that maybe .not shouldn't cancel .not but rather some other keyword like .but or .and. This was discussed quite a bit in #785 and ultimately decided that there's problems with every approach (including the current one), and that any benefit gained by changing the behavior isn't great enough to be worth a breaking change.
Most helpful comment
@tomalec One thing you could do is unset an existing
negatedflag from within your custom assertion:Having two
notflags cancel each other out is problematic in some situations, such as:The typical counterargument to this is that maybe
.notshouldn't cancel.notbut rather some other keyword like.butor.and. This was discussed quite a bit in #785 and ultimately decided that there's problems with every approach (including the current one), and that any benefit gained by changing the behavior isn't great enough to be worth a breaking change.