enzyme-to-json-mock-props
v1.0.0
Published
it gives you the ability to mock props generated via enzyme-to-json
Downloads
2
Maintainers
Readme
enzyme-to-json-mock-props
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]"
/>
`;