jest-serializer-no-mock-function

1.0.0 • Public • Published

Jest snapshot serializer that prevents serializing mocked functions

Upon upgrading to Jest 22 I've ran into snapshot size increase due to serialization of mocked functions. This pacakge makes it serialize to a normal function.

Install

Add the package as a dev-dependency:

# With npm 
npm install --save-dev jest-serializer-no-mock-function
 
# With yarn 
yarn add --dev jest-serializer-no-mock-function

Update package.json to let Jest know about the serializer:

"jest"{
  "snapshotSerializers": ["jest-serializer-no-mock-function"]
}

Example

test('Mock test', () => {
  const mock = jest.fn().mockName('myMock');
 
  mock('hello', { foo: 'bar' });
 
  expect(mock).toMatchSnapshot();
});

Output with:

exports[`Mock test 1`] = `[Function]`;

Output without:

exports[`Mock test 1`] = `
[MockFunction myMock] {
  "calls": Array [
    Array [
      "hello",
      Object {
        "foo": "bar",
      },
    ],
  ],
}
`;

Package Sidebar

Install

npm i jest-serializer-no-mock-function

Weekly Downloads

59

Version

1.0.0

License

MIT

Last publish

Collaborators

  • tornjv