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); }; /** diff --git a/test/test.js b/test/test.js index c87a94d..78817ef 100644 --- a/test/test.js +++ b/test/test.js @@ -33,6 +33,14 @@ describe('chai-immutable', function () { }); describe('equal method', function () { + it( + 'should fail 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( + 'should fail when only the "expected" value is an Immutable collection', + function () { + var fn = function () { assert.equal([], List()); }; + assert.throw(fn); + } + ); + it('should be true when compared structure is equal', function () { assert.equal(list3, List.of(1, 2, 3)); });