tj / should.js

BDD style assertions for node.js -- test framework agnostic
MIT License
2.75k stars 195 forks source link

should.be.null and should.be.undefined? #27

Closed ghost closed 12 years ago

ghost commented 12 years ago

Right now I am using should.equal null and should.equal undefined.

Would it be better if you could use these assertions directly?

UPDATE: I just realized that you cannot have methods to null and undefined :)

tj commented 12 years ago

haha yeah that's a big no unfortunately, for null or undefined checks I usually use node's assert since you can just do assert(!err) etc

ghost commented 8 years ago

I struggled to write the should statement for undefined tests. The following doesn't work.

    target.should.be.undefined();

I found the following solutions.

    (target === undefined).should.be.true()

if can also write it as a type check

   (typeof target).should.be.equal('undefined');

Not sure if the above is the right way, but it does work.

fchambo commented 8 years ago

You can use this:

should(target).not.be.ok;

Or this:

should.not.exist(target)