项目作者: keplersj

项目描述 :
Serializer to display react-helmet-async data in Jest Snapshots
高级语言: TypeScript
项目地址: git://github.com/keplersj/jest-serializer-react-helmet-async.git
创建时间: 2019-12-16T22:05:27Z
项目社区:https://github.com/keplersj/jest-serializer-react-helmet-async

开源协议:ISC License

下载


jest-serializer-react-helmet-async

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

Installation

Install preset using npm:

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

or yarn:

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

Usage

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

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

or package.json:

  1. {
  2. "jest": {
  3. "snapshotSerializers": ["jest-serializer-react-helmet-async"]
  4. }
  5. }

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:

  1. import * as React from "react";
  2. import renderer from "react-test-renderer";
  3. import { HelmetProvider } from "react-helmet-async";
  4. describe("App", () => {
  5. it("renders as expected", () => {
  6. const context = {};
  7. const tree = renderer
  8. .create(
  9. <HelmetProvider context={context}>
  10. <App ></App>
  11. </HelmetProvider>
  12. )
  13. .toJSON();
  14. expect(tree).toMatchSnapshot();
  15. expect(context.helmet).toMatchSnapshot();
  16. });
  17. });

License

Copyright 2019 Kepler Sticka-Jones. Licensed ISC