deno.land / x / jotai@v1.8.4 / tests / useAtomValue.test.tsx

useAtomValue.test.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
import { StrictMode } from 'react'import { fireEvent, render } from '@testing-library/react'import { atom, useAtomValue, useSetAtom } from 'jotai'import { getTestProvider } from './testUtils'
const Provider = getTestProvider()
it('useAtomValue basic test', async () => { const countAtom = atom(0)
const Counter = () => { const count = useAtomValue(countAtom) const setCount = useSetAtom(countAtom)
return ( <> <div>count: {count}</div> <button onClick={() => setCount(count + 1)}>dispatch</button> </> ) } const { findByText, getByText } = render( <StrictMode> <Provider> <Counter /> </Provider> </StrictMode> )
await findByText('count: 0') fireEvent.click(getByText('dispatch')) await findByText('count: 1')})
jotai

Version Info

Tagged at
a year ago