Skip to content

Commit 7267aa6

Browse files
committed
reset stylesheet for all tests
1 parent 652a8f7 commit 7267aa6

File tree

4 files changed

+35
-42
lines changed

4 files changed

+35
-42
lines changed

src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const toHaveStyleRule = require('./toHaveStyleRule')
2-
const styleSheetSerializer = require('./styleSheetSerializer')
3-
const { resetStyleSheet } = require('./utils')
1+
const toHaveStyleRule = require('./toHaveStyleRule');
2+
const styleSheetSerializer = require('./styleSheetSerializer');
3+
const { resetStyleSheet } = require('./utils');
44

5-
resetStyleSheet()
5+
global.beforeEach(resetStyleSheet);
66

7-
expect.addSnapshotSerializer(styleSheetSerializer)
8-
expect.extend({ toHaveStyleRule })
7+
expect.addSnapshotSerializer(styleSheetSerializer);
8+
expect.extend({ toHaveStyleRule });

test/setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { configure } from 'enzyme';
22
import Adapter from 'enzyme-adapter-react-16';
33

4+
import '../src';
5+
46
configure({ adapter: new Adapter() });

test/styleSheetSerializer.spec.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { mount, shallow } from 'enzyme';
33
import React from 'react';
44
import renderer from 'react-test-renderer';
55
import styled, { ThemeContext, ThemeProvider } from 'styled-components';
6-
import '../src';
7-
import { resetStyleSheet } from '../src/utils';
86

97
const toMatchSnapshot = (name, component) => {
108
expect(renderer.create(component).toJSON()).toMatchSnapshot('react-test-renderer');
@@ -20,10 +18,6 @@ const shallowWithTheme = (tree, theme) => {
2018
return shallow(tree);
2119
};
2220

23-
beforeEach(() => {
24-
resetStyleSheet();
25-
});
26-
2721
it('null', () => {
2822
expect(null).toMatchSnapshot();
2923
});

test/utils.spec.js

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
1-
const { getHashes } = require('../src/utils');
1+
const {
2+
__PRIVATE__: { masterSheet },
3+
} = require('styled-components');
24

3-
jest.mock('styled-components', () => ({
4-
ServerStyleSheet: true,
5-
__PRIVATE__: {
6-
masterSheet: {
7-
names: new Map([['sc-1', new Set(['a'])], ['sc-2', new Set(['b', 'c'])], ['sc-3', new Set(['d', 'e'])]]),
8-
toString() {
9-
return `
10-
<style data-styled="active">
11-
.sc-1 {}
12-
data-styled.g1[id="sc-1"]{content:"sc-1,"}
13-
.a { color: red; }
14-
</style>
15-
<style data-styled="active">
16-
.sc-2 {}
17-
data-styled.g2[id="sc-2"]{content:"sc-2,"}
18-
.b { color: green; }
19-
.c { color: blue; }
20-
</style>
21-
<style data-styled="active">
22-
.sc-3 {}
23-
data-styled.g3[id="sc-3"]{content:"sc-3,"}
24-
.d { color: pink; }
25-
.e { color: indianred; }
26-
</style>
27-
`;
28-
},
29-
},
30-
},
31-
}));
5+
const { getHashes } = require('../src/utils');
326

337
it('extracts hashes', () => {
8+
masterSheet.names = new Map([['sc-1', new Set(['a'])], ['sc-2', new Set(['b', 'c'])], ['sc-3', new Set(['d', 'e'])]]);
9+
masterSheet.toString = function() {
10+
return `
11+
<style data-styled="active">
12+
.sc-1 {}
13+
data-styled.g1[id="sc-1"]{content:"sc-1,"}
14+
.a { color: red; }
15+
</style>
16+
<style data-styled="active">
17+
.sc-2 {}
18+
data-styled.g2[id="sc-2"]{content:"sc-2,"}
19+
.b { color: green; }
20+
.c { color: blue; }
21+
</style>
22+
<style data-styled="active">
23+
.sc-3 {}
24+
data-styled.g3[id="sc-3"]{content:"sc-3,"}
25+
.d { color: pink; }
26+
.e { color: indianred; }
27+
</style>
28+
`;
29+
};
30+
3431
expect(getHashes()).toEqual(['sc-1', 'a', 'sc-2', 'b', 'c', 'sc-3', 'd', 'e']);
3532
});

0 commit comments

Comments
 (0)