Giter Club home page Giter Club logo

Comments (3)

SimenB avatar SimenB commented on July 1, 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 🤔

from jest.

VictorGlindasPaf avatar VictorGlindasPaf commented on July 1, 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.

from jest.

ldeveber avatar ldeveber commented on July 1, 2024

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

from jest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.