tj / should.js

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

null #5

Closed weepy closed 11 years ago

weepy commented 13 years ago

i suppose there's probably not much we can do here , but it's a shame we can't handle null :

null.should.not.be.ok

results in "Cannot read property 'should' of null"

i was wondering if we could support some kind of alternate calling scheme where the should comes first :

should.be.ok(null)

weepy commented 13 years ago

All - just found you can do: should.ok(null)

Perhaps we could rename the library to is, which works for both calling methods:

x.is.within(5)

is.ok(5)

!!!

aseemk commented 13 years ago

I like the should.be.ok idea, but in general, I've been longing for the word "exist" instead of "ok". I've forked this and am in the middle of implementing should.exist() as an alias for should.ok(). What do you guys think?

aseemk commented 13 years ago

Here's my implementation: https://github.com/visionmedia/should.js/pull/11

(It would be nice if you could import a pull request into an existing issue.)

aseemk commented 13 years ago

TJ just pulled my change -- thanks! You can now do:

should.exist(foo);        // will throw if null or undefined
foo.should.equal(bar);    // safe assertion to make now

I can't close this issue so someone else may want to.