Permalink
Browse files

Fix deep object comparison between 'true', {}, and [].

  • Loading branch information...
bradcavanagh committed May 2, 2013
1 parent e18c483 commit 6f3ad6a18dd762f1c5d2b289ac87d528586acf37
Showing with 24 additions and 0 deletions.
  1. +6 −0 chai.js
  2. +6 −0 lib/chai/utils/eql.js
  3. +6 −0 test/expect.js
  4. +6 −0 test/should.js
View
@@ -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.

Show comment
Hide comment
@domenic

domenic May 2, 2013

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

@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;
View
@@ -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;
View
@@ -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');
View
@@ -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');

0 comments on commit 6f3ad6a

Please sign in to comment.