I'm modifying a Jest test which looks like this:
it("footer exists as expected", () => {
const tree = renderer.create(<Footer />).toJSON()
expect(tree).toMatchSnapshot()
})
The snapshot looks like this:
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`test header consistency footer exists as expected 1`] = `
<footer
className="makeStyles-footer-1"
id="footer"
role="contentinfo"
>
<div
className="makeStyles-content-2"
>
<div>
... (version number within a nested HTML element)
</footer>
`;
Nested within the HTML is a version number that I'd like to exclude from the snapshot comparison. How could this be done? (Am looking for the simplest way.)
Note: Did come across a small bit of Jest documentation which looked promising but only excluded an example for a simple JSON object: https://jestjs.io/docs/snapshot-testing#property-matchers - and this answer does similar. Could this be adapted for a nested HTML structure?