|
1 | 1 | import * as React from 'react' |
| 2 | +import * as CSSModules from 'react-css-modules' |
2 | 3 | import { shallow, ShallowWrapper } from 'enzyme' |
3 | 4 |
|
4 | 5 | import { App } from '../app' |
5 | 6 | import { Child } from '../child' |
6 | 7 | import { ChildUsual } from '../child-usual' |
7 | 8 |
|
| 9 | +import * as appStyles from '../app.css' |
| 10 | +import * as childStyles from '../child.css' |
| 11 | + |
8 | 12 |
|
9 | 13 | test('App can initialize', () => { |
10 | 14 | const wrapper = shallow(React.createElement(App)) |
11 | 15 | expect(wrapper.length).toBe(1) |
12 | 16 | }) |
13 | 17 |
|
| 18 | +test('App text has class', () => { |
| 19 | + const wrapper = shallowCSSModulesRenderer(App, appStyles) |
| 20 | + expect(wrapper.find('#app-text').hasClass('my-style')).toBe(true) |
| 21 | +}) |
| 22 | + |
14 | 23 | test('Child can initialize', () => { |
15 | 24 | const wrapper = shallow(React.createElement(Child)) |
16 | 25 | expect(wrapper.length).toBe(1) |
17 | 26 | }) |
18 | 27 |
|
| 28 | +test('Child text has class', () => { |
| 29 | + const wrapper = shallowCSSModulesRenderer(Child, childStyles) |
| 30 | + expect(wrapper.find('#child-text').hasClass('my-style')).toBe(true) |
| 31 | +}) |
| 32 | + |
19 | 33 | test('ChildUsual can initialize', () => { |
20 | 34 | const wrapper = shallow(React.createElement(ChildUsual)) |
21 | 35 | expect(wrapper.length).toBe(1) |
22 | 36 | }) |
| 37 | + |
| 38 | +test('ChildUsual text has class', () => { |
| 39 | + const wrapper = shallowCSSModulesRenderer(ChildUsual) |
| 40 | + expect(wrapper.find('#child-usual-text').hasClass('my-style')).toBe(true) |
| 41 | +}) |
| 42 | + |
| 43 | + |
| 44 | + |
| 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 | + } |
| 51 | +} |
0 commit comments