Skip to content

Commit 38df73b

Browse files
scottty881cjihrig
authored andcommitted
print expected value in assertion messages
1 parent df0113b commit 38df73b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ internals.equal = function (value, options) {
275275
const compare = this._flags.shallow ? (a, b) => a === b
276276
: (a, b) => Hoek.deepEqual(a, b, settings);
277277

278-
return this.assert(compare(this._ref, value), 'equal specified value', this._ref, value);
278+
return this.assert(compare(this._ref, value), `equal specified value: ${internals.display(value)}`, this._ref, value);
279279
};
280280

281281
internals.addMethod(['equal', 'equals'], internals.equal);

test/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ describe('expect()', () => {
349349
}
350350

351351
Code.settings.comparePrototypes = origPrototype;
352-
Hoek.assert(exception.message === 'Expected {} to equal specified value', exception);
352+
Hoek.assert(exception.message === 'Expected {} to equal specified value: {}', exception);
353353
done();
354354
});
355355

@@ -1573,7 +1573,7 @@ describe('expect()', () => {
15731573
exception = err;
15741574
}
15751575

1576-
Hoek.assert(exception.message === 'Expected { foo: 1 } to equal specified value', exception);
1576+
Hoek.assert(exception.message === 'Expected { foo: 1 } to equal specified value: { foo: 2 }', exception);
15771577
done();
15781578
});
15791579

@@ -1605,7 +1605,21 @@ describe('expect()', () => {
16051605
exception = err;
16061606
}
16071607

1608-
Hoek.assert(exception.message === 'Expected [ \'a\' ] to equal specified value', exception);
1608+
Hoek.assert(exception.message === 'Expected [ \'a\' ] to equal specified value: [ \'a\' ]', exception);
1609+
done();
1610+
});
1611+
1612+
it('prints the specified value', (done) => {
1613+
1614+
let exception = false;
1615+
try {
1616+
Code.expect('test').to.equal('junk');
1617+
}
1618+
catch (err) {
1619+
exception = err;
1620+
}
1621+
1622+
Hoek.assert(exception.message === 'Expected \'test\' to equal specified value: \'junk\'', exception);
16091623
done();
16101624
});
16111625
});

0 commit comments

Comments
 (0)