Skip to content

Instantly share code, notes, and snippets.

@macku
Last active February 4, 2018 22:11
Show Gist options
  • Save macku/2c06eac0fc3388ff86d5274c3419af80 to your computer and use it in GitHub Desktop.
Save macku/2c06eac0fc3388ff86d5274c3419af80 to your computer and use it in GitHub Desktop.
Jest Puppe Shots example
// https://github.com/macku/jest-puppe-shots
const { mount } = require('jest-puppeshots');
// 1. Sync API
test('should render <Foo> component', () => {
const wrapper = mount(
<MyComponent className="my-component">
<strong>Hello World!</strong>
</MyComponent>
);
expect(wrapper).toMatchScreenshot();
});
// 2. Pass viewport
test('should render <Foo> component', () => {
const wrapper = mount(
<MyComponent className="my-component">
<strong>Hello World!</strong>
</MyComponent>
);
expect(wrapper).toMatchScreenshot({ // Pass viewport size
width: 800,
height: 600
});
});
// 3, Async API ?
test('should render <Foo> component', async () => {
const wrapper = await mount(
<FooComponent>
<BooComponent></BooComponent>
</FooComponent>
);
const children = await wrapper.find('.custom-class');
await children.simulate('click');
expect(children).toMatchScreenshot();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment