Skip to content

Commit 386f756

Browse files
committed
Add tests for theming
1 parent 858601d commit 386f756

2 files changed

Lines changed: 134 additions & 0 deletions

File tree

src/tests/__snapshots__/functional.spec.jsx.snap

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,35 @@ exports[`functional tests should use props on remount 2`] = `
109109
color: red;
110110
}"
111111
`;
112+
113+
exports[`functional tests theming should update theme 1`] = `
114+
".button-1-id {
115+
color: green;
116+
background-color: white;
117+
}"
118+
`;
119+
120+
exports[`functional tests theming should update theme 2`] = `
121+
".button-1-id {
122+
color: yellow;
123+
background-color: blue;
124+
}"
125+
`;
126+
127+
exports[`functional tests theming should work with ThemeProvider 1`] = `
128+
".button-1-id {
129+
color: red;
130+
background-color: black;
131+
}"
132+
`;
133+
134+
exports[`functional tests theming should work with nested ThemeProvider 1`] = `
135+
".button-1-id {
136+
color: green;
137+
background-color: white;
138+
}
139+
.button-2-id {
140+
color: blue;
141+
background-color: yellow;
142+
}"
143+
`;

src/tests/functional.spec.jsx

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'react-dom'
22
import React from 'react'
3+
import {ThemeProvider} from 'theming'
34
import {mount} from 'enzyme'
45

56
import {
@@ -131,4 +132,105 @@ describe('functional tests', () => {
131132

132133
wrapper.unmount()
133134
})
135+
136+
describe('theming', () => {
137+
it('should work with ThemeProvider', () => {
138+
const theme = {
139+
color: {
140+
primary: 'red',
141+
secondary: 'black'
142+
}
143+
}
144+
145+
const Button = styled('button')({
146+
color: props => props.theme.color.primary,
147+
backgroundColor: props => props.theme.color.secondary,
148+
})
149+
150+
const wrapper = mount(
151+
<ThemeProvider theme={theme}>
152+
<Button />
153+
</ThemeProvider>
154+
)
155+
const {sheet} = styled
156+
157+
assertSheet(sheet)
158+
159+
wrapper.unmount()
160+
})
161+
162+
it('should update theme', () => {
163+
const initialTheme = {
164+
color: {
165+
primary: 'green',
166+
secondary: 'white'
167+
}
168+
}
169+
170+
const Button = styled('button')({
171+
color: props => props.theme.color.primary,
172+
backgroundColor: props => props.theme.color.secondary,
173+
})
174+
175+
const App = (props: {theme: Object}) => (
176+
<ThemeProvider theme={props.theme}>
177+
<Button />
178+
</ThemeProvider>
179+
)
180+
181+
const wrapper = mount(<App theme={initialTheme} />)
182+
const {sheet} = styled
183+
184+
assertSheet(sheet)
185+
186+
const nextTheme = {
187+
color: {
188+
primary: 'yellow',
189+
secondary: 'blue'
190+
}
191+
}
192+
wrapper.setProps({theme: nextTheme})
193+
194+
assertSheet(sheet)
195+
196+
wrapper.unmount()
197+
})
198+
199+
it('should work with nested ThemeProvider', () => {
200+
const themes = [{
201+
color: {
202+
primary: 'green',
203+
secondary: 'white'
204+
}
205+
}, {
206+
color: {
207+
primary: 'blue',
208+
secondary: 'yellow'
209+
}
210+
}]
211+
212+
const Button = styled('button')({
213+
color: props => props.theme.color.primary,
214+
backgroundColor: props => props.theme.color.secondary,
215+
})
216+
217+
const App = () => (
218+
<ThemeProvider theme={themes[0]}>
219+
<div>
220+
<Button />
221+
<ThemeProvider theme={themes[1]}>
222+
<Button />
223+
</ThemeProvider>
224+
</div>
225+
</ThemeProvider>
226+
)
227+
228+
const wrapper = mount(<App />)
229+
const {sheet} = styled
230+
231+
assertSheet(sheet)
232+
233+
wrapper.unmount()
234+
})
235+
})
134236
})

0 commit comments

Comments
 (0)