moll / js-must

An assertion library for JavaScript and Node.js with a friendly BDD syntax (awesome.must.be.true()). It ships with many expressive matchers and is test runner and framework agnostic. Follows RFC 2119 with its use of MUST. Good stuff and well tested.
Other
336 stars 35 forks source link

empty() assertion passes with a not empty object #9

Closed Nicolab closed 10 years ago

Nicolab commented 10 years ago

Hello,

must(new Error('whh')).empty(); // passes.

It should fail ?

moll commented 10 years ago

Hey!

That's funny, but it indeed turns out an instance of Error has no enumerable properties which Must.prototype.empty looks for to decide on emptiness. It would be nice if message were enumerable, but I guess it's because message in the Error's prototype (Error.prototype.message) is also set non-enumerable.

You can see it like this:

Object.getOwnPropertyDescriptor(Error.prototype, "message")
{ value: '',
  writable: true,
  enumerable: false,
  configurable: true }
Nicolab commented 10 years ago

Indeed Error API

I had not seen that empty() assertion check on the enumerable properties.

Thanks