Permalink
Browse files

Fix should.be.instanceOf() failure on Date

* Improvement to #56 to address should.be.instanceOf() failure on Date
reported at #65
* More tests for should.be.instanceOf()
  • Loading branch information...
1 parent e3d4244 commit 035b3ba0906d9213612cc8cc2676ddbdc9bb218c @skovalyov skovalyov committed Feb 5, 2013
Showing with 18 additions and 2 deletions.
  1. +2 −2 lib/should.js
  2. +16 −0 test/should.test.js
View
@@ -72,7 +72,7 @@ exports.not.exist = exports.not.exists = function(obj, msg){
Object.defineProperty(Object.prototype, 'should', {
set: function(){},
get: function(){
- return new Assertion(Object(this).valueOf());
+ return new Assertion(this.valueOf() == this ? this.valueOf() : this);
},
configurable: true
});
@@ -301,7 +301,7 @@ Assertion.prototype = {
equal: function(val, desc){
this.assert(
- val.valueOf() === this.obj
+ val === this.obj
, function(){ return 'expected ' + this.inspect + ' to equal ' + i(val) + (desc ? " | " + desc : "") }
, function(){ return 'expected ' + this.inspect + ' to not equal ' + i(val) + (desc ? " | " + desc : "") }
, val);
View
@@ -106,6 +106,14 @@ module.exports = {
function Foo(){}
new Foo().should.be.an.instanceof(Foo);
+ new Date().should.be.an.instanceof(Date);
+
+ var tobi = { name: 'Tobi', age: 2 };
+ tobi.should.be.an.instanceof(Object);
+
+ var getSomething = function() {return "something"};
+ getSomething.should.be.an.instanceof(Function);
+
err(function(){
(3).should.an.instanceof(Foo);
}, "expected 3 to be an instance of Foo");
@@ -119,6 +127,14 @@ module.exports = {
function Foo(){}
new Foo().should.be.an.instanceOf(Foo);
+ new Date().should.be.an.instanceOf(Date);
+
+ var tobi = { name: 'Tobi', age: 2 };
+ tobi.should.be.an.instanceOf(Object);
+
+ var getSomething = function() {return "something"};
+ getSomething.should.be.an.instanceOf(Function);
+
err(function(){
(9).should.an.instanceOf(Foo);
}, "expected 9 to be an instance of Foo");

0 comments on commit 035b3ba

Please sign in to comment.