Skip to content

Commit

Permalink
Fix the output to make the unexpected-dom test suite pass
Browse files Browse the repository at this point in the history
I'll make a follow-up PR that ensures that the rest of the amend handling is correct.
  • Loading branch information
sunesimonsen committed Nov 17, 2018
1 parent 63ce989 commit 3ab670a
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ module.exports = expect => {
output
.i()
.block(function() {
this.amend(propertyOutput).amend(delimiterOutput);
this.append(propertyOutput).amend(delimiterOutput);
if (!keyInValue[key]) {
this.sp().annotationBlock(function() {
this.error('should be removed');
Expand Down Expand Up @@ -1711,7 +1711,7 @@ module.exports = expect => {
);

this.append(propertyOutput)
.append(delimiterOutput)
.amend(delimiterOutput)
.sp()
.error('// should be moved');
} else if (type === 'insert') {
Expand Down Expand Up @@ -1754,11 +1754,11 @@ module.exports = expect => {
this.block(function() {
if (type === 'remove') {
this.append(propertyOutput)
.append(delimiterOutput)
.amend(delimiterOutput)
.sp()
.error('// should be removed');
} else if (type === 'equal') {
this.append(propertyOutput).append(
this.append(propertyOutput).amend(
delimiterOutput
);
} else {
Expand All @@ -1773,12 +1773,10 @@ module.exports = expect => {
output: output.clone()
});
if (valueDiff && valueDiff.inline) {
this.append(valueDiff).append(
delimiterOutput
);
this.append(valueDiff).amend(delimiterOutput);
} else {
this.append(propertyOutput)
.append(delimiterOutput)
.amend(delimiterOutput)
.sp()
.annotationBlock(function() {
this.omitSubject = diffItem.value;
Expand Down
83 changes: 83 additions & 0 deletions test/assertions/to-satisfy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,89 @@ describe('to satisfy assertion', () => {
']'
);
});

it('handles multi-line items correctly', () => {
class Box {
constructor(value) {
this.value = value;
}
}

const clonedExpect = expect.clone().addType({
name: 'box',
identify: value => value && value instanceof Box,
inspect: (box, depth, output, inspect) =>
output.block(output => {
output.text('╔═══╗').nl();
output.text(`║ ${box.value} ║`).nl();
output.text('╚═══╝');
}),
equal: (a, b, equal) => a.value === b.value
});

expect(
() => {
clonedExpect(
[new Box(0), new Box(1), new Box(2), new Box(4), new Box(3)],
'to satisfy',
[new Box(1), new Box(0), new Box(2), new Box(3)]
);
},
'to throw',
`\
expected
[
╔═══╗
║ 0 ║
╚═══╝,
╔═══╗
║ 1 ║
╚═══╝,
╔═══╗
║ 2 ║
╚═══╝,
╔═══╗
║ 4 ║
╚═══╝,
╔═══╗
║ 3 ║
╚═══╝
]
to satisfy
[
╔═══╗
║ 1 ║
╚═══╝,
╔═══╗
║ 0 ║
╚═══╝,
╔═══╗
║ 2 ║
╚═══╝,
╔═══╗
║ 3 ║
╚═══╝
]
[
╔═══╗ // should equal ╔═══╗
║ 0 ║ // ║ 1 ║
╚═══╝, // ╚═══╝
╔═══╗ // should equal ╔═══╗
║ 1 ║ // ║ 0 ║
╚═══╝, // ╚═══╝
╔═══╗
║ 2 ║
╚═══╝,
╔═══╗ // should equal ╔═══╗
║ 4 ║ // ║ 3 ║
╚═══╝, // ╚═══╝
╔═══╗ // should be removed
║ 3 ║
╚═══╝
]`.replace(/^ /gm, '')
);
});
});

it('should render a missing item expected to satisfy an expect.it', () => {
Expand Down

0 comments on commit 3ab670a

Please sign in to comment.