tj / should.js

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

unexpected behavior of instanceOf() on wrapped primitive values #156

Closed stimberm closed 10 years ago

stimberm commented 10 years ago

I would expect the following code to work, but it does not.

var should = require('should'); // version 2.1.1

var five = Object(5);

(five instanceof Number).should.be.true; // works
should(five).be.an.instanceof(Number);   // throws
five.should.be.an.instanceof(Number);    // throws
five.should.be.an.instanceOf(Number);    // throws
btd commented 10 years ago

It is known issue. Because everyone tried to do assertion on numbers which are wrapped to Numbers. Internally should unwrap all standard wrappers to its own values to work with them not with wrappers (and anyone will expect to see value not a wrapper reference).

See:

(5).should.be.exactly(5);

As you see 5 will be wrapped to Number(5) and then call happen.

That was one of the reasons i added type assertions:

should(five).be.a.Number; // works