Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/serialize-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const extractStack = require('./extract-stack');

function serializeValue(value) {
return prettyFormat(value, {
callToJSON: false,
plugins: [reactTestPlugin],
highlight: true
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"dependencies": {
"@ava/babel-preset-stage-4": "^1.0.0",
"@ava/babel-preset-transform-test-files": "^2.0.0",
"@ava/pretty-format": "^1.0.0",
"@ava/pretty-format": "^1.1.0",
"arr-flatten": "^1.0.1",
"array-union": "^1.0.1",
"array-uniq": "^1.0.2",
Expand Down
8 changes: 6 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -914,11 +914,15 @@ Assert that `value` is not equal to `expected`.

### `.deepEqual(value, expected, [message])`

Assert that `value` is deep equal to `expected`.
Assert that `value` is deep equal to `expected`. This is based on [Lodash' `isEqual()`](https://lodash.com/docs/4.17.4#isEqual):

> Performs a deep comparison between two values to determine if they are equivalent.
>
> *Note*: This method supports comparing arrays, array buffers, booleans, date objects, error objects, maps, numbers, `Object` objects, regexes, sets, strings, symbols, and typed arrays. `Object` objects are compared by their own, not inherited, enumerable properties. Functions and DOM nodes are compared by strict equality, i.e. `===`.

### `.notDeepEqual(value, expected, [message])`

Assert that `value` is not deep equal to `expected`.
Assert that `value` is not deep equal to `expected`. The inverse of `.deepEqual()`.

### `.throws(function|promise, [error, [message]])`

Expand Down
27 changes: 27 additions & 0 deletions test/serialize-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const serialize = require('../lib/serialize-error');

function serializeValue(value) {
return prettyFormat(value, {
callToJSON: false,
plugins: [reactTestPlugin],
highlight: true
});
Expand Down Expand Up @@ -93,3 +94,29 @@ test('skip actual and expected if output is off', t => {
t.notOk(serializedErr.expectedType);
t.end();
});

test('does not call toJSON() when serializing actual and expected', t => {
const err = Object.assign(new Error(), {
showOutput: true,
actual: {
foo: 'bar',
toJSON() {
return {
foo: 'BAR'
};
}
},
expected: {
foo: 'thud',
toJSON() {
return {
foo: 'BAR'
};
}
}
});

const serializedErr = serialize(err);
t.notSame(serializedErr.actual, serializedErr.expected);
t.end();
});