@@ -6,8 +6,7 @@ import { App } from '../app'
6
6
import { Child } from '../child'
7
7
import { ChildUsual } from '../child-usual'
8
8
9
- import * as appStyles from '../app.css'
10
- import * as childStyles from '../child.css'
9
+ import * as dummyStyles from './dummy.css'
11
10
12
11
13
12
test ( 'App can initialize' , ( ) => {
@@ -16,7 +15,7 @@ test('App can initialize', () => {
16
15
} )
17
16
18
17
test ( 'App text has class' , ( ) => {
19
- const wrapper = shallowCSSModulesRenderer ( App , appStyles )
18
+ const wrapper = shallow ( decoratedElement ( App ) )
20
19
expect ( wrapper . find ( '#app-text' ) . hasClass ( 'my-style' ) ) . toBe ( true )
21
20
} )
22
21
@@ -26,7 +25,7 @@ test('Child can initialize', () => {
26
25
} )
27
26
28
27
test ( 'Child text has class' , ( ) => {
29
- const wrapper = shallowCSSModulesRenderer ( Child , childStyles )
28
+ const wrapper = shallow ( decoratedElement ( Child ) )
30
29
expect ( wrapper . find ( '#child-text' ) . hasClass ( 'my-style' ) ) . toBe ( true )
31
30
} )
32
31
@@ -36,16 +35,12 @@ test('ChildUsual can initialize', () => {
36
35
} )
37
36
38
37
test ( 'ChildUsual text has class' , ( ) => {
39
- const wrapper = shallowCSSModulesRenderer ( ChildUsual )
38
+ const wrapper = shallow ( decoratedElement ( ChildUsual ) )
40
39
expect ( wrapper . find ( '#child-usual-text' ) . hasClass ( 'my-style' ) ) . toBe ( true )
41
40
} )
42
41
43
42
44
43
45
- function shallowCSSModulesRenderer < T , U > ( component : any , styles ?: any ) : ShallowWrapper < T , U > {
46
- if ( styles ) {
47
- return shallow ( React . createElement ( CSSModules ( component , styles ) ) ) as any
48
- } else {
49
- return shallow ( React . createElement ( component ) ) as any
50
- }
44
+ function decoratedElement ( component : typeof React . Component ) : React . ComponentElement < any , any > {
45
+ return React . createElement ( CSSModules ( component , dummyStyles , { allowMultiple : true } ) )
51
46
}
0 commit comments