Open VictorGlindasPaf opened 4 months ago
Primitive types, except
symbol
.
Great... π Not sure how we can deal with this properly π€
To expand on this, it doesn't only seem to be an issue with jest symbols, but with anything that throws and can't be structurally cloned.
For example if I run a test that calls axios and the test throws an AxiosError
, I get the same vague DataCloneError
.
Another side note; I don't seem to get this error with .toMatchObject
, since the error that throws doesn't contain the symbols that .toEqual
does.
I just hit this too, but my output is:
β Test suite failed to run
DataCloneError: function () {
return fn.apply(this, arguments);
} could not be cloned.
at reportSuccess (node_modules/jest-worker/build/workers/threadChild.js:98:34)
If I change my test to be like:
test('blah', () => {
try {
// all test contents here
} catch (e) {
console.log(e);
}
});
I can actually get the real failure. Not a workaround by any means :(
console.log
JestAssertionError: expect(received).toHaveBeenCalledOnce(expected)
Expected mock function to have been called exactly once, but it was called:
0 times
at Object.toHaveBeenCalledOnce (~/project/src/components/__tests__/Thing.test.tsx:86:25) {
matcherResult: {
pass: false,
message: 'expect(received).toHaveBeenCalledOnce(expected)\n' +
'\n' +
'Expected mock function to have been called exactly once, but it was called:\n' +
' 0 times',
actual: [Function: mockConstructor] {
_isMockFunction: true,
getMockImplementation: [Function (anonymous)],
mock: [Getter/Setter],
mockClear: [Function (anonymous)],
mockReset: [Function (anonymous)],
mockRestore: [Function (anonymous)],
mockReturnValueOnce: [Function (anonymous)],
mockResolvedValueOnce: [Function (anonymous)],
mockRejectedValueOnce: [Function (anonymous)],
mockReturnValue: [Function (anonymous)],
mockResolvedValue: [Function (anonymous)],
mockRejectedValue: [Function (anonymous)],
mockImplementationOnce: [Function (anonymous)],
withImplementation: [Function: bound withImplementation],
mockImplementation: [Function (anonymous)],
mockReturnThis: [Function (anonymous)],
mockName: [Function (anonymous)],
getMockName: [Function (anonymous)]
}
}
}
Just wanted to chime in here that I ran into the same issue as well.
β Test suite failed to run
DataCloneError: () => somefunction() could not be cloned.
There was an actual test failure but it wouldn't show up in test output because the error.
Not an actual solution, but running the jest test --workerThreads=false
is how I was able to see the actual error and able to fix my tests.
Version
29.70
Steps to reproduce
Create a test with
expect.any
, or any other jest helpers that uses symbols.Run the test with worker threads:
Expected behavior
I should get a regular test failure message, that actually tells me what expect is failing.
Actual behavior
I get an error that tells me next to nothing.
Additional context
No response
Environment