11import 'react-dom'
22import React from 'react'
3- import { stripIndent } from 'common-tags'
43import { mount } from 'enzyme'
54
65import {
@@ -15,7 +14,6 @@ let styled
1514
1615const mockNameGenerators = ( ) => {
1716 let styledCounter = 0
18- let jssCounter = 0
1917
2018 jest . mock ( '../utils/generateTagName' )
2119 jest . mock ( 'jss/lib/utils/generateClassName' )
@@ -25,7 +23,12 @@ const mockNameGenerators = () => {
2523
2624 // $FlowIgnore
2725 generateTagName . mockImplementation ( ( tagName : string ) => `${ tagName } -${ ++ styledCounter } ` )
28- generateClassName . mockImplementation ( rule => `${ rule . name } -${ ++ jssCounter } ` )
26+ generateClassName . mockImplementation ( rule => `${ rule . name } -id` )
27+ }
28+
29+ const assertSheet = ( sheet ) => {
30+ expect ( sheet . toString ( ) ) . toMatchSnapshot ( )
31+ expect ( getCss ( sheet ) ) . toBe ( removeWhitespace ( sheet . toString ( ) ) )
2932}
3033
3134describe ( 'functional tests' , ( ) => {
@@ -45,56 +48,9 @@ describe('functional tests', () => {
4548 const wrapper = mount ( < App /> )
4649 const sheet = styled . mountSheet ( )
4750
48- expect ( sheet . toString ( ) ) . toBe ( stripIndent `
49- .div-1-1 {
50- margin: 50px;
51- }
52- .header-2-2 {
53- padding: 10px;
54- }
55- .h1-5-3 {
56- color: red;
57- }
58- .section-3-4 {
59- color: red;
60- }
61- .button-6-5 {
62- margin: 0;
63- }
64- .button-7-6 {
65- margin: 10px;
66- }
67- .section-4-7 {
68- color: yellow;
69- }
70- ` )
71-
51+ assertSheet ( sheet )
7252 wrapper . setProps ( { margin : 20 } )
73-
74- expect ( sheet . toString ( ) ) . toBe ( stripIndent `
75- .div-1-1 {
76- margin: 50px;
77- }
78- .header-2-2 {
79- padding: 10px;
80- }
81- .h1-5-3 {
82- color: red;
83- }
84- .section-3-4 {
85- color: red;
86- }
87- .button-6-5 {
88- margin: 0;
89- }
90- .button-7-6 {
91- margin: 20px;
92- }
93- .section-4-7 {
94- color: yellow;
95- }
96- ` )
97-
53+ assertSheet ( sheet )
9854 wrapper . unmount ( )
9955 } )
10056
@@ -132,42 +88,9 @@ describe('functional tests', () => {
13288 const wrapper = mount ( < App /> )
13389 const sheet = styled . mountSheet ( )
13490
135- expect ( sheet . toString ( ) ) . toBe ( stripIndent `
136- .button-1 {
137- font-size: 12px;
138- }
139- .div-1-2 {
140- padding: 15px;
141- }
142- .div-3-3:hover .button-1 {
143- color: green;
144- }
145- .div-4-7:hover .button-1 {
146- color: red;
147- }
148- ` )
149-
150- expect ( getCss ( sheet ) ) . toBe ( removeWhitespace ( sheet . toString ( ) ) )
151-
91+ assertSheet ( sheet )
15292 wrapper . setProps ( { primary : true } )
153-
154- expect ( sheet . toString ( ) ) . toBe ( stripIndent `
155- .button-1 {
156- font-size: 12px;
157- }
158- .div-1-2 {
159- padding: 15px;
160- }
161- .div-3-3:hover .button-1 {
162- color: red;
163- }
164- .div-4-7:hover .button-1 {
165- color: green;
166- }
167- ` )
168-
169- expect ( getCss ( sheet ) ) . toBe ( removeWhitespace ( sheet . toString ( ) ) )
170-
93+ assertSheet ( sheet )
17194 wrapper . unmount ( )
17295 } )
17396} )
0 commit comments