Skip to content
Permalink
Browse files

Fix the error message when an object is exhaustively satisfied agains…

…t an object, and some keys are missing
  • Loading branch information...
papandreou committed Mar 2, 2017
1 parent 5fb884a commit 4ee3d589ab003da5c5ed84cb27dc4aa4d82ae680
Showing with 18 additions and 2 deletions.
  1. +3 −0 lib/assertions.js
  2. +15 −2 test/assertions/to-satisfy.spec.js
@@ -1305,6 +1305,9 @@ module.exports = function (expect) {
if (promiseByKey[key].isRejected()) {
output.error('// missing:').sp();
valueOutput = output.clone().appendErrorMessage(promiseByKey[key].reason());
} else {
output.error('// missing').sp();
valueOutput = output.clone().error('should satisfy').sp().block(inspect(value[key]));
}
} else {
output.error('// missing').sp();
@@ -796,6 +796,19 @@ describe('to satisfy assertion', function () {
it('should treat a missing subject property the same as a value property of undefined', function () {
expect({}, 'to exhaustively satisfy', { foo: undefined });
});

// Regression test for #380
it('should display a proper error message when a missing key is satisfied against an expect.it', function () {
expect(function () {
expect({}, 'to exhaustively satisfy', {foo: expect.it('to be undefined')});
}, 'to throw',
"expected {} to exhaustively satisfy { foo: expect.it('to be undefined') }\n" +
"\n" +
"{\n" +
" // missing foo: should satisfy expect.it('to be undefined')\n" +
"}"
);
});
});

it('should support satisfying against a regexp', function () {
@@ -1766,12 +1779,12 @@ describe('to satisfy assertion', function () {
}, 'to throw', function (err) {
// Compensate for V8 5.1+ setting { foo: function () {} }.foo.name === 'foo'
// http://v8project.blogspot.dk/2016/04/v8-release-51.html
expect(err.getErrorMessage('text').toString().replace('function foo', 'function '), 'to satisfy',
expect(err.getErrorMessage('text').toString().replace(/function foo/g, 'function '), 'to satisfy',
"expected {} to satisfy { bar: 123, foo: function () {} }\n" +
"\n" +
"{\n" +
" // missing bar: 123\n" +
" foo:\n" + // FIXME: Come up with something better
" // missing foo: should satisfy function () {}\n" +
"}"
);
});

0 comments on commit 4ee3d58

Please sign in to comment.
You can’t perform that action at this time.