Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: DataCloneError: Symbol(jest.asymmetricMatcher) could not be cloned using --workerThreads. #15078

Open
VictorGlindasPaf opened this issue May 21, 2024 · 3 comments

Comments

@VictorGlindasPaf
Copy link

VictorGlindasPaf commented May 21, 2024

Version

29.70

Steps to reproduce

Create a test with expect.any, or any other jest helpers that uses symbols.

it("works", () => {
  expect({}).toEqual({
    value1: 0,
    value2: expect.any(String),
  });
})

Run the test with worker threads:

jest --workerThreads --maxWorkers=50%

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.

  ● Test suite failed to run

    DataCloneError: Symbol(jest.asymmetricMatcher) could not be cloned.

      at reportSuccess (../../node_modules/jest-worker/build/workers/threadChild.js:99:34)

Seed:        1878439832
Test Suites: 1 failed, 1 total

Additional context

No response

Environment

System:
    OS: macOS 14.0
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 3.5.1 - ~/.nvm/versions/node/v20.10.0/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
@SimenB
Copy link
Member

SimenB commented May 21, 2024

https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#javascript_types

Primitive types, except symbol.

Great... 😅 Not sure how we can deal with this properly 🤔

@SimenB SimenB changed the title [Bug]: DataCloneError: Symbol(jest.asymmetricMatcher) could not be cloned. [Bug]: DataCloneError: Symbol(jest.asymmetricMatcher) could not be cloned using --workerThreads. May 21, 2024
@VictorGlindasPaf
Copy link
Author

VictorGlindasPaf commented May 23, 2024

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.

@ldeveber
Copy link

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)]
        }
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants