Skip to content

Commit

Permalink
Merge pull request #441 from unexpectedjs/feature/onlyCompactSubjectW…
Browse files Browse the repository at this point in the history
…henThereIsADiff

Only compact the subject when there is a diff
  • Loading branch information
papandreou committed May 5, 2018
2 parents a49d6c4 + 57da7c4 commit b18bb77
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ expect(
```

```output
expected array to have an item satisfying to have an item satisfying to be a number
expected [ [ '0', '1' ], [ '5', '6' ], [ '7', '8' ] ]
to have an item satisfying to have an item satisfying to be a number
```

Here a another example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ expect(
```

```output
expected object to have a value satisfying
expected { foo: [ 10, 11, 12 ], bar: [ 14, 15, 16 ], baz: [ 17, 18, 19 ] } to have a value satisfying
to have items satisfying expect.it('to be a number')
.and('to be below', 8)
```
18 changes: 13 additions & 5 deletions lib/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,9 @@ module.exports = expect => {
expect.fail({
message(output) {
output.append(
expect.standardErrorMessage(output.clone(), { compact: true })
expect.standardErrorMessage(output.clone(), {
compact: err && err._isUnexpected && err.hasDiff()
})
);
},
diff(output) {
Expand Down Expand Up @@ -1103,7 +1105,9 @@ module.exports = expect => {
expect.fail({
message(output) {
output.append(
expect.standardErrorMessage(output.clone(), { compact: true })
expect.standardErrorMessage(output.clone(), {
compact: err && err._isUnexpected && err.hasDiff()
})
);
},
diff(output) {
Expand Down Expand Up @@ -1166,10 +1170,12 @@ module.exports = expect => {
);
})
)
.caught(e =>
.caught(err =>
expect.fail(output => {
output.append(
expect.standardErrorMessage(output.clone(), { compact: true })
expect.standardErrorMessage(output.clone(), {
compact: err && err._isUnexpected && err.hasDiff()
})
);
})
);
Expand All @@ -1192,7 +1198,9 @@ module.exports = expect => {
err => {
expect.fail(output => {
output.append(
expect.standardErrorMessage(output.clone(), { compact: true })
expect.standardErrorMessage(output.clone(), {
compact: err && err._isUnexpected && err.hasDiff()
})
);
});
}
Expand Down
6 changes: 5 additions & 1 deletion test/assertions/to-have-an-item-satisfying.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ describe('to have an item satisfying assertion', function() {
);
},
'to throw',
'expected array to have an item satisfying\n' +
'expected\n' +
'[\n' +
' [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]\n' +
']\n' +
'to have an item satisfying\n' +
'function (item) {\n' +
' expect.fail(function (output) {\n' +
" output.text('foo').nl().text('bar');\n" +
Expand Down

0 comments on commit b18bb77

Please sign in to comment.