Serializer to display react-helmet-async data in Jest Snapshots
npm install jest-serializer-react-helmet-asyncJest Snapshot serializer to visualize react-helmet-async data alongside component snapshots.
Install preset using npm:
``shell`
npm install --save-dev jest-serializer-react-helmet-async
or yarn:
`shell`
yarn add --dev jest-serializer-react-helmet-async
Configure Jest to use the serializer in jest.config.js:
`js`
module.exports = {
snapshotSerializers: ["jest-serializer-react-helmet-async"],
};
or package.json:
`json`
{
"jest": {
"snapshotSerializers": ["jest-serializer-react-helmet-async"]
}
}
Unlike jest-serializer-react-helmet, this serializer does not automatically prepend the serialized data to the snapshots of your React components. You must add an assert for react-helmet-async to be serialized.
Your test should like similar to the following:
`js
import * as React from "react";
import renderer from "react-test-renderer";
import { HelmetProvider } from "react-helmet-async";
describe("App", () => {
it("renders as expected", () => {
const context = {};
const tree = renderer
.create(
)
.toJSON();
expect(tree).toMatchSnapshot();
expect(context.helmet).toMatchSnapshot();
});
});
`
- jest-runner-prettier - Use Jest to check your codebase against prettierjest-preset-gatsby
- - Jest preset to ease unit testing a Gatsby projectjest-serializer-json-ld-script
- - Jest snapshot serializer to better visualize React