enzyme-to-json-mock-props
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

enzyme-to-json-mock-props npm Build Status Coverage Status

it gives you the ability to mock props generated via enzyme-to-json.

Install

npm install enzyme-to-json-mock-props

Example

Assuming you are using enzyme-to-json/serializer as snapshotSerializers, example.

import * as React from "react";
import { shallow } from "enzyme";
import mockProps from "enzyme-to-json-mock-props";
 
const SubComponent = () => <div />;
 
const Component = props => (
  <SubComponent {...props} style={{ background: "red", color: "black" }} />
);
 
describe("my snapshot", () => {
  const props = {
    foo: {
      bar: 123
    },
    foobar: "asd",
    asd: {
      qwe: 321
    }
  };
  it("should render properly", () => {
    const wrapper = shallow(<Component {...props} />);
    expect(
      mockProps(wrapper, ["foo", "foobar", "style", "qwe"])
    ).toMatchSnapshot();
  });
});

before (without mockProps):

exports[`enzyme-to-json-mock-props should render properly 1`] = `
<SubComponent
  asd={
    Object {
      "qwe": 321,
    }
  }
  foo={
    Object {
      "bar": 123,
    }
  }
  foobar="asd"
  style={
    Object {
      "background": "red",
      "color": "black",
    }
  }
/>
`;

after (with mockProps):

exports[`enzyme-to-json-mock-props should mock the indicated props 1`] = `
<SubComponent
  asd={
    Object {
      "qwe": 321,
    }
  }
  foo="[foo]"
  foobar="[foobar]"
  style="[style]"
/>
`;

Dependents (0)

Package Sidebar

Install

npm i enzyme-to-json-mock-props

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

7.68 kB

Total Files

10

Last publish

Collaborators

  • sirlisko