Skip to content

Commit

Permalink
object diff: Fixed indentation of objects to be removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jan 21, 2015
1 parent 32b641c commit c55f3f6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/types.js
Expand Up @@ -200,6 +200,7 @@ module.exports = function (expect) {
if (conflicting) {
if (!(key in expected)) {
annotation.error('should be removed');
isInlineDiff = true;
} else {
var keyDiff = diff(actual[key], expected[key]);
if (!keyDiff || (keyDiff && !keyDiff.inline)) {
Expand Down
28 changes: 28 additions & 0 deletions test/unexpected.spec.js
Expand Up @@ -1728,6 +1728,34 @@ describe('unexpected', function () {
"}");
});

it('indents removed objects correctly', function () {
var str = 'abcdefghijklmnopqrstuvwxyz';
expect(function () {
expect({foo: {a: str, b: str, c: str, d: str, e: str}}, 'to equal', {});
}, 'to throw',
'expected\n' +
'{\n' +
' foo: {\n' +
" a: 'abcdefghijklmnopqrstuvwxyz',\n" +
" b: 'abcdefghijklmnopqrstuvwxyz',\n" +
" c: 'abcdefghijklmnopqrstuvwxyz',\n" +
" d: 'abcdefghijklmnopqrstuvwxyz',\n" +
" e: 'abcdefghijklmnopqrstuvwxyz'\n" +
' }\n' +
'}\n' +
'to equal {}\n' +
'\n' +
'{\n' +
' foo: {\n' +
" a: 'abcdefghijklmnopqrstuvwxyz',\n" +
" b: 'abcdefghijklmnopqrstuvwxyz',\n" +
" c: 'abcdefghijklmnopqrstuvwxyz',\n" +
" d: 'abcdefghijklmnopqrstuvwxyz',\n" +
" e: 'abcdefghijklmnopqrstuvwxyz'\n" +
' } // should be removed\n' +
'}');
});

describe('with a custom type', function () {
function MysteryBox(value) {
this.propertyName = 'prop' + Math.floor(1000 * Math.random());
Expand Down

0 comments on commit c55f3f6

Please sign in to comment.