Skip to content

Commit

Permalink
Merge pull request #18 from matthewwithanm/immutable-actuals-2
Browse files Browse the repository at this point in the history
Fix broken assert.equal assertion when not applied on a Collection
  • Loading branch information
astorije committed Jul 9, 2015
2 parents a5b6b46 + d1d4c5a commit f4a68b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion chai-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ module.exports = function (chai, utils) {
*/

var assert = chai.assert;
var originalEqual = assert.equal;

/**
* ### .equal(actual, expected)
Expand All @@ -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);
};

/**
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down Expand Up @@ -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));
});
Expand Down

0 comments on commit f4a68b1

Please sign in to comment.