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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.