Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 913a63e

Browse files
gretzkyGretzky
authored andcommitted
reconfigure the way we test styled-components
1 parent 62e6fce commit 913a63e

File tree

14 files changed

+579
-51
lines changed

14 files changed

+579
-51
lines changed

app/components/Header/tests/A.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from 'react';
2-
import { mount, render } from 'enzyme';
2+
import { mount } from 'enzyme';
3+
import renderer from 'react-test-renderer';
4+
import 'jest-styled-components';
35

46
import A from '../A';
57

68
describe('<A />', () => {
7-
it('should render an <a> tag', () => {
8-
const renderedComponent = render(<A />);
9-
expect(renderedComponent.find('a').length).toEqual(1);
9+
it('should match the snapshot', () => {
10+
const renderedComponent = renderer.create(<A />).toJSON();
11+
expect(renderedComponent).toMatchSnapshot();
1012
});
1113

1214
it('should have a className attribute', () => {
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
import React from 'react';
2-
import { mount, render } from 'enzyme';
2+
import { mount } from 'enzyme';
3+
import renderer from 'react-test-renderer';
4+
import 'jest-styled-components';
35

46
import Img from '../Img';
57

68
describe('<Img />', () => {
7-
it('should render an <img> tag', () => {
8-
const renderedComponent = render(<Img src={'http://example.com/test.jpg'} alt={'test'} />);
9-
expect(renderedComponent.find('img').length).toEqual(1);
9+
it('should match the snapshot', () => {
10+
const renderedComponent = renderer
11+
.create(<Img src={'http://example.com/test.jpg'} alt={'test'} />)
12+
.toJSON();
13+
expect(renderedComponent).toMatchSnapshot();
1014
});
1115

1216
it('should have a className attribute', () => {
13-
const renderedComponent = mount(<Img src={'http://example.com/test.jpg'} alt={'test'} />);
17+
const renderedComponent = mount(
18+
<Img src={'http://example.com/test.jpg'} alt={'test'} />
19+
);
1420
expect(renderedComponent.find('img').prop('className')).toBeDefined();
1521
});
1622

1723
it('should adopt a valid attribute', () => {
18-
const renderedComponent = mount(<Img src={'http://example.com/test.jpg'} alt={'test'} />);
24+
const renderedComponent = mount(
25+
<Img src={'http://example.com/test.jpg'} alt={'test'} />
26+
);
1927
expect(renderedComponent.find('img').prop('alt')).toEqual('test');
2028
});
2129

2230
it('should not adopt an invalid attribute', () => {
23-
const renderedComponent = mount(<Img src={'http://example.com/test.jpg'} attribute={'test'} alt={'test'} />);
31+
const renderedComponent = mount(
32+
<Img
33+
src={'http://example.com/test.jpg'}
34+
attribute={'test'}
35+
alt={'test'}
36+
/>
37+
);
2438
expect(renderedComponent.find('img').prop('attribute')).toBeUndefined();
2539
});
2640
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<A /> should match the snapshot 1`] = `
4+
.c0 {
5+
color: #41addd;
6+
padding: 2em 0;
7+
}
8+
9+
.c0:hover {
10+
color: #6cc0e5;
11+
}
12+
13+
<a
14+
className="c0"
15+
/>
16+
`;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<Img /> should match the snapshot 1`] = `
4+
.c0 {
5+
width: 100%;
6+
margin: 0 auto;
7+
display: block;
8+
}
9+
10+
<img
11+
alt="test"
12+
className="c0"
13+
src="http://example.com/test.jpg"
14+
/>
15+
`;

0 commit comments

Comments
 (0)