From 08edf4a2b79a1b9de59b0cbde1848ccb15faf589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Sat, 14 Nov 2015 23:57:48 +0000 Subject: [PATCH] Fix #7: Make sure the displayed output on failures is human readable --- chai-immutable.js | 7 ++++--- test/test.js | 23 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/chai-immutable.js b/chai-immutable.js index fa04fb0..b2681bc 100644 --- a/chai-immutable.js +++ b/chai-immutable.js @@ -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); diff --git a/test/test.js b/test/test.js index 5f51b8b..07d24b2 100644 --- a/test/test.js +++ b/test/test.js @@ -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 () { @@ -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()); }); }); @@ -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()); }); });