Skip to content

Commit

Permalink
Add assert.equal support (relates to #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
astorije committed Mar 14, 2015
1 parent 3aac99a commit 1bcfae6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
34 changes: 34 additions & 0 deletions chai-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ var Collection = Immutable.Collection;
module.exports = function (chai, utils) {
var Assertion = chai.Assertion;

/**
* ## BDD API Reference
*/

/**
* ### .empty
*
Expand Down Expand Up @@ -251,4 +255,34 @@ module.exports = function (chai, utils) {
else _super.apply(this, arguments);
};
});

/**
* ## TDD API Reference
*/

/**
* ### .equal(actual, expected)
*
* Asserts that the values of the target are equvalent to the values of
* `collection`. Note that `.strictEqual` and `.deepEqual` assert exactly like
* `.equal` in the context of Immutable data structures.
*
* ```js
* var a = List.of(1, 2, 3);
* var b = List.of(1, 2, 3);
* assert.equal(a, b);
* ```
*
* @name equal
* @param {Collection} actual
* @param {Collection} expected
* @api public
*/

chai.assert.equal = function (actual, expected) {
if (actual instanceof Collection) {
return new Assertion(actual).equal(expected);
}
else return chai.assert.equal;
};
};
17 changes: 17 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ describe('chai-immutable', function () {
});

describe('assert interface', function () {
describe('equal assertion', function () {
it('should be true when compared structure is equal', function () {
assert.equal(list3, List.of(1, 2, 3));
});

it('should be false when compared structure not equal', function () {
assert.notEqual(list3, new List());
});

it('should not affect the original assertion', function () {
assert.equal(42, 42);
assert.equal(3, '3');
assert.notEqual('oui', 'non');
assert.notEqual({ foo: 'bar' }, { foo: 'bar' });
});
});

describe('unoverridden strictEqual and deepEqual assertions', function () {
it('should be true when compared structure is equal', function () {
assert.strictEqual(list3, List.of(1, 2, 3));
Expand Down

0 comments on commit 1bcfae6

Please sign in to comment.