-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy paththeme-provider.dom.js
37 lines (34 loc) · 1018 Bytes
/
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
/** @jsx jsx */
import 'test-utils/next-env'
import { render, fireEvent } from '@testing-library/react'
import { safeQuerySelector } from 'test-utils'
import * as React from 'react'
import { jsx, ThemeProvider } from '@emotion/react'
beforeEach(() => {
document.head.innerHTML = ''
})
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>
)
}
}
const { container } = render(<ThemeTest />)
expect(container).toMatchSnapshot()
fireEvent.click(safeQuerySelector('#the-thing'))
expect(container).toMatchSnapshot()
})