/
theme-provider.dom.js
45 lines (40 loc) · 1.2 KB
/
theme-provider.dom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// @flow
/** @jsx jsx */
import 'test-utils/next-env'
import 'test-utils/dev-mode'
import { throwIfFalsy, safeQuerySelector } from 'test-utils'
import * as React from 'react'
import { jsx, ThemeProvider } from '@emotion/core'
import { render } from 'react-dom'
test('provider with theme value that changes', () => {
class ThemeTest extends React.Component<*, *> {
state = { theme: { color: 'hotpink', padding: 4 } }
render() {
return (
<ThemeProvider theme={this.state.theme}>
<div
id="the-thing"
onClick={() => {
this.setState({ theme: { color: 'hotpink', padding: 8 } })
}}
css={({ color, padding }) => ({
color,
padding
})}
/>
</ThemeProvider>
)
}
}
let head = throwIfFalsy(document.head)
let body = throwIfFalsy(document.body)
head.innerHTML = ''
body.innerHTML = '<div id="root"></div>'
let root = safeQuerySelector('#root')
render(<ThemeTest />, root)
expect(root).toMatchSnapshot()
throwIfFalsy(safeQuerySelector('#the-thing')).click()
expect(root).toMatchSnapshot()
head.innerHTML = ''
body.innerHTML = '<div id="root"></div>'
})