Skip to content

Commit

Permalink
Fix #7: Make sure the displayed output on failures is human readable
Browse files Browse the repository at this point in the history
  • Loading branch information
astorije committed Nov 14, 2015
1 parent 39540ff commit 08edf4a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
7 changes: 4 additions & 3 deletions chai-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@
if (obj && obj instanceof Collection) {
this.assert(
Immutable.is(obj, collection),
'expected #{this} to equal #{exp}',
'expected #{this} to not equal #{exp}',
collection
'expected #{act} to equal #{exp}',
'expected #{act} to not equal #{exp}',
collection.toString(),
obj.toString()
);
}
else _super.apply(this, arguments);
Expand Down
23 changes: 21 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ var Stack = Immutable.Stack;
* Test helper to check that a given function (wrapping the assertion) will
* fail.
*/
function fail(fn) {
expect(fn).to.throw(chai.AssertionError);
function fail(fn, msg) {
if (msg !== undefined) expect(fn).to.throw(chai.AssertionError, msg);
else expect(fn).to.throw(chai.AssertionError);
}

describe('chai-immutable (' + typeEnv + ')', function () {
Expand Down Expand Up @@ -123,6 +124,15 @@ describe('chai-immutable (' + typeEnv + ')', function () {
expect([]).to.not.equal(List());
});

// See https://github.com/astorije/chai-immutable/issues/7
it('should display a helpful failure output on big objects', function () {
var actual = new Map({ foo: 'foo foo foo foo foo foo foo foo' });
var expected = new Map({ bar: 'bar bar bar bar bar bar bar bar' });
fail(function () {
expect(actual).to.equal(expected);
}, /(foo ?){8}.+(bar ?){8}/);
});

it('should fail given a non-Immutable value', function () {
fail(function () { expect([]).to.equal(List()); });
});
Expand Down Expand Up @@ -522,6 +532,15 @@ describe('chai-immutable (' + typeEnv + ')', function () {
assert.equal(3, '3');
});

// See https://github.com/astorije/chai-immutable/issues/7
it('should display a helpful failure output on big objects', function () {
var actual = new Map({ foo: 'foo foo foo foo foo foo foo foo' });
var expected = new Map({ bar: 'bar bar bar bar bar bar bar bar' });
fail(function () {
assert.equal(actual, expected);
}, /(foo ?){8}.+(bar ?){8}/);
});

it('should fail given a non-Immutable value', function () {
fail(function () { assert.equal([], List()); });
});
Expand Down

0 comments on commit 08edf4a

Please sign in to comment.