Skip to content
Serializer to display react-helmet-async data in Jest Snapshots
TypeScript JavaScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.dependabot
.github/workflows
src
.gitignore
LICENSE
README.md
jest.config.js
package-lock.json
package.json
stryker.conf.js
tsconfig.json

README.md

jest-serializer-react-helmet-async

Jest Snapshot serializer to visualize react-helmet-async data alongside component snapshots.

Installation

Install preset using npm:

npm install --save-dev jest-serializer-react-helmet-async

or yarn:

yarn add --dev jest-serializer-react-helmet-async

Usage

Configure Jest to use the serializer in jest.config.js:

module.exports = {
  snapshotSerializers: ["jest-serializer-react-helmet-async"]
};

or package.json:

{
  "jest": {
    "snapshotSerializers": ["jest-serializer-react-helmet-async"]
  }
}

In your tests

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:

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(
        <HelmetProvider context={context}>
          <App />
        </HelmetProvider>
      )
      .toJSON();

    expect(tree).toMatchSnapshot();
    expect(context.helmet).toMatchSnapshot();
  });
});

Related Packages

License

Copyright 2019 Kepler Sticka-Jones. Licensed ISC

You can’t perform that action at this time.