-
Notifications
You must be signed in to change notification settings - Fork 19
/
update-time-context.spec.tsx
51 lines (44 loc) · 1.25 KB
/
update-time-context.spec.tsx
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
46
47
48
49
50
51
import { fireEvent, getByRole, render } from '@testing-library/react'
import { useContext } from 'react'
import { UpdateTimeContext } from './update-time-context'
const setUpdateTime = jest.fn()
function Content() {
const { utc, setUpdateTimeContext } = useContext(UpdateTimeContext)
return (
<div>
<button onClick={() => setUpdateTimeContext && setUpdateTimeContext({ utc: true })}>
Click {utc.toString()}
</button>
</div>
)
}
describe('UpdateTimeContext', () => {
it('should render successfully', () => {
const { baseElement } = render(
<UpdateTimeContext.Provider
value={{
...{ utc: false },
setUpdateTimeContext: setUpdateTime,
}}
>
<Content />
</UpdateTimeContext.Provider>
)
expect(baseElement).toBeTruthy()
})
it('should change context UTC boolean', async () => {
const { baseElement } = render(
<UpdateTimeContext.Provider
value={{
...{ utc: false },
setUpdateTimeContext: setUpdateTime,
}}
>
<Content />
</UpdateTimeContext.Provider>
)
const button = getByRole(baseElement, 'button')
fireEvent.click(button)
expect(baseElement.textContent).toBe('Click false')
})
})