From 2f46af85f2c2b0800d29e08063043963df9d2419 Mon Sep 17 00:00:00 2001 From: Grant Snodgrass Date: Sun, 14 Jan 2018 16:02:54 +0000 Subject: [PATCH] fix: remove Chai frames from `.deep.equal` stack --- lib/chai/core/assertions.js | 5 ++++- test/expect.js | 16 ++++++++++++++++ test/should.js | 13 +++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index 968e6e1b2..14b56cf53 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -1016,7 +1016,10 @@ module.exports = function (chai, _) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); if (flag(this, 'deep')) { - return this.eql(val); + var prevLockSsfi = flag(this, 'lockSsfi'); + flag(this, 'lockSsfi', true); + this.eql(val); + flag(this, 'lockSsfi', prevLockSsfi); } else { this.assert( val === obj diff --git a/test/expect.js b/test/expect.js index 8d658f2ff..062f8034b 100644 --- a/test/expect.js +++ b/test/expect.js @@ -1181,6 +1181,22 @@ describe('expect', function () { it('deep.equal(val)', function(){ expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' }); expect({ foo: 'bar' }).not.to.deep.equal({ foo: 'baz' }); + + err(function(){ + expect({foo: 'bar'}).to.deep.equal({foo: 'baz'}, 'blah'); + }, "blah: expected { foo: 'bar' } to deeply equal { foo: 'baz' }"); + + err(function(){ + expect({foo: 'bar'}, 'blah').to.deep.equal({foo: 'baz'}); + }, "blah: expected { foo: 'bar' } to deeply equal { foo: 'baz' }"); + + err(function(){ + expect({foo: 'bar'}).to.not.deep.equal({foo: 'bar'}, 'blah'); + }, "blah: expected { foo: 'bar' } to not deeply equal { foo: 'bar' }"); + + err(function(){ + expect({foo: 'bar'}, 'blah').to.not.deep.equal({foo: 'bar'}); + }, "blah: expected { foo: 'bar' } to not deeply equal { foo: 'bar' }"); }); it('deep.equal(/regexp/)', function(){ diff --git a/test/should.js b/test/should.js index 1eb10a46f..064c9bc13 100644 --- a/test/should.js +++ b/test/should.js @@ -1022,6 +1022,19 @@ describe('should', function() { }, "blah: expected '4' to equal 4"); }); + it('deep.equal(val)', function(){ + ({ foo: 'bar' }).should.deep.equal({ foo: 'bar' }); + ({ foo: 'bar' }).should.not.deep.equal({ foo: 'baz' }); + + err(function(){ + ({foo: 'bar'}).should.deep.equal({foo: 'baz'}, 'blah'); + }, "blah: expected { foo: 'bar' } to deeply equal { foo: 'baz' }"); + + err(function(){ + ({foo: 'bar'}).should.not.deep.equal({foo: 'bar'}, 'blah'); + }, "blah: expected { foo: 'bar' } to not deeply equal { foo: 'bar' }"); + }); + it('empty', function(){ function FakeArgs() {}; FakeArgs.prototype.length = 0;