1.0.0 • Published 6 years ago
jest-serializer-no-mock-function v1.0.0
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",
},
],
],
}
`;
1.0.0
6 years ago