Enzyme serializer
waynebrantley opened this issue · 4 comments
I added enzyme-to-json as my serializer.
I tried to map out some properties with
map: (json) => ({
...json,
props: omitBy(json.props, (val, key) => key === "className"),
}),
These map out fine for normal snapshots, but using yours I can never get it to work. Can you advise?
Can you please share a bit more code?
import "jest"
import { createSerializer } from "enzyme-to-json"
import omitBy from "lodash/omitBy"
import { addSerializer } from 'jest-specific-snapshot'
const customSerializer = createSerializer({
noKey: true,
mode: "deep",
map: (json) => {
return ({
...json,
props: omitBy(json.props, (val, key) => key === "className"),
})
},
})
expect.addSnapshotSerializer(customSerializer)
addSerializer(customSerializer)
I put a console.log in the map function and it was called if it was a normal expect(wrapper).toMatchSnapshot()
but nothing logged when
expect(tree).toMatchSpecificSnapshot(snapshotFileName)
The use case is I am using this with storyshots from storybook.
Some components that get saved set the html id attribute to a unique id that is different everytime. So, I wanted to just remove the id attribute from the snapshot.
Alternatively, I could do "id":expect.any(string) - but that does not do arbitrary nesting (and your toMatchSpecificSnapshot does not accept property matchers anyway.
I didn't forget this 😅 . Just need some time to dive into this problem.
Ok, so I am back to this. Where is this code located for you?
Also, check this out: https://github.com/storybooks/storybook/tree/next/addons/storyshots/storyshots-core#snapshotserializers