From a4d510d6f4d1f0fb66e9ac3d8ba5a7f5b41c5df4 Mon Sep 17 00:00:00 2001 From: Matthew Dapena-Tretter Date: Wed, 10 Jun 2015 16:57:22 -0400 Subject: [PATCH 1/3] Test that Immutable comparison is used when "expected" value is an Immutable collection These tests currently fail. The result is some false positives! --- test/test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test.js b/test/test.js index c87a94d..54f3b70 100644 --- a/test/test.js +++ b/test/test.js @@ -33,6 +33,14 @@ describe('chai-immutable', function () { }); describe('equal method', function () { + it( + 'fails when only the "expected" value is an Immutable collection', + function () { + var fn = function () { expect([]).to.equal(List()); }; + expect(fn).to.throw(Error); + } + ); + it('should be true when compared structure is equal', function () { expect(list3).to.equal(List.of(1, 2, 3)); }); @@ -297,6 +305,14 @@ describe('chai-immutable', function () { describe('TDD interface', function () { describe('equal assertion', function () { + it( + 'fails when only the "expected" value is an Immutable collection', + function () { + var fn = function () { assert.equal([], List()); }; + expect(fn).to.throw(Error); + } + ); + it('should be true when compared structure is equal', function () { assert.equal(list3, List.of(1, 2, 3)); }); From 6972e4e008fb9ed385e2171a328430f52aa0ea1d Mon Sep 17 00:00:00 2001 From: Matthew Dapena-Tretter Date: Wed, 10 Jun 2015 16:57:36 -0400 Subject: [PATCH 2/3] Fall back to original `equal` method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You wouldn’t expect that this is necessary, however `assert.equal` and the BDD version aren’t actually the same! The BDD version uses strict equality while the “assert” version doesn’t. TIL. This fixes the bug with testing equality of an Array and Immutable collection with the "assert" style. --- chai-immutable.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/chai-immutable.js b/chai-immutable.js index 2a9316d..0acaee9 100644 --- a/chai-immutable.js +++ b/chai-immutable.js @@ -416,6 +416,7 @@ module.exports = function (chai, utils) { */ var assert = chai.assert; + var originalEqual = assert.equal; /** * ### .equal(actual, expected) @@ -437,10 +438,15 @@ module.exports = function (chai, utils) { */ assert.equal = function (actual, expected) { + /* + * It seems like we shouldn't actually need this check, however, + * `assert.equal` actually behaves differently than its BDD counterpart! + * Namely, the BDD version is strict while the "assert" one isn't. + */ if (actual instanceof Collection) { return new Assertion(actual).equal(expected); } - else return assert.equal; + else return originalEqual(actual, expected); }; /** From d1d4c5a69ca692d5f7f9eac66d1a9ad110ea4673 Mon Sep 17 00:00:00 2001 From: Matthew Dapena-Tretter Date: Wed, 8 Jul 2015 21:08:52 -0400 Subject: [PATCH 3/3] Match established test styles --- test/test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test.js b/test/test.js index 54f3b70..78817ef 100644 --- a/test/test.js +++ b/test/test.js @@ -34,7 +34,7 @@ describe('chai-immutable', function () { describe('equal method', function () { it( - 'fails when only the "expected" value is an Immutable collection', + 'should fail when only the "expected" value is an Immutable collection', function () { var fn = function () { expect([]).to.equal(List()); }; expect(fn).to.throw(Error); @@ -306,10 +306,10 @@ describe('chai-immutable', function () { describe('TDD interface', function () { describe('equal assertion', function () { it( - 'fails when only the "expected" value is an Immutable collection', + 'should fail when only the "expected" value is an Immutable collection', function () { var fn = function () { assert.equal([], List()); }; - expect(fn).to.throw(Error); + assert.throw(fn); } );