Skip to content

Commit

Permalink
Fix deep object comparison between 'true', {}, and [].
Browse files Browse the repository at this point in the history
  • Loading branch information
bradcavanagh committed May 2, 2013
1 parent e18c483 commit 6f3ad6a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions chai.js
Expand Up @@ -3118,6 +3118,12 @@ function _deepEqual(actual, expected, memos) {
if (actual === expected) {
return true;

} else if (typeof actual !== typeof expected) {
return false;

} else if (Object.prototype.toString.call(actual) !== Object.prototype.toString.call(expected)) {

This comment has been minimized.

Copy link
@domenic

domenic May 2, 2013

Seems not good, this will prevent expect(arguments).to.deep.equal([1, 2, 3]).

return false;

} else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
if (actual.length != expected.length) return false;

Expand Down
6 changes: 6 additions & 0 deletions lib/chai/utils/eql.js
Expand Up @@ -21,6 +21,12 @@ function _deepEqual(actual, expected, memos) {
if (actual === expected) {
return true;

} else if (typeof actual !== typeof expected) {
return false;

} else if (Object.prototype.toString.call(actual) !== Object.prototype.toString.call(expected)) {
return false;

} else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
if (actual.length != expected.length) return false;

Expand Down
6 changes: 6 additions & 0 deletions test/expect.js
Expand Up @@ -283,6 +283,12 @@ suite('expect', function () {
expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
expect(1).to.eql(1);
expect('4').to.not.eql(4);
expect(true).to.not.eql({});
expect(true).to.not.eql([]);
expect({}).to.not.eql([]);
expect([]).to.not.eql({});
expect({}).to.eql({});
expect([]).to.eql([]);

err(function(){
expect(4).to.eql(3, 'blah');
Expand Down
6 changes: 6 additions & 0 deletions test/should.js
Expand Up @@ -270,6 +270,12 @@ suite('should', function() {
({ foo: 'bar' }).should.eql({ foo: 'bar' });
(1).should.eql(1);
'4'.should.not.eql(4);
true.should.not.eql({});
true.should.not.eql([]);
({}).should.not.eql([]);
([]).should.not.eql({});
({}).should.eql({});
([]).should.eql([]);

err(function(){
(4).should.eql(3, 'blah');
Expand Down

0 comments on commit 6f3ad6a

Please sign in to comment.