How do I use Chai to verify that some variable does not exist?
That is to say, my js doesn't have a statement var never_declared, and I want to verify that there isn't any such variable.
I have tried all of following, but Karma keeps complaining "Can't find variable: never_declared". Which is exactly what I'm trying to test.
should.not.exist(never_declared);
expect(never_declared).to.not.exist;
expect(never_declared).to.not.exist;
expect(never_declared).to.be.undefined;
expect(never_declared).to.be.an('undefined');
assert.isNotObject(never_declared);
assert.isUndefined(never_declared);
If Karma has a problem with it you can use another valid Chai form like:
expect(typeof never_declared).to.eq('undefined');
or
expect(typeof never_declared === "undefined").to.be.true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With