deno.land / x / jotai@v1.8.4 / tests / provider.test.tsx
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import { StrictMode } from 'react'import { render, waitFor } from '@testing-library/react'import { atom, useAtom } from 'jotai'import { getTestProvider } from './testUtils'
const Provider = getTestProvider(true)
it('uses initial values from provider', async () => { const countAtom = atom(1) const petAtom = atom('cat')
const Display = () => { const [count] = useAtom(countAtom) const [pet] = useAtom(petAtom)
return ( <> <p>count: {count}</p> <p>pet: {pet}</p> </> ) }
const { getByText } = render( <StrictMode> <Provider initialValues={[ [countAtom, 0], [petAtom, 'dog'], ]}> <Display /> </Provider> </StrictMode> )
await waitFor(() => { getByText('count: 0') getByText('pet: dog') })})
it('only uses initial value from provider for specific atom', async () => { const countAtom = atom(1) const petAtom = atom('cat')
const Display = () => { const [count] = useAtom(countAtom) const [pet] = useAtom(petAtom)
return ( <> <p>count: {count}</p> <p>pet: {pet}</p> </> ) }
const { getByText } = render( <StrictMode> <Provider initialValues={[[petAtom, 'dog']]}> <Display /> </Provider> </StrictMode> )
await waitFor(() => { getByText('count: 1') getByText('pet: dog') })})
it('renders correctly without children', () => { render( <StrictMode> <Provider /> </StrictMode> )})
Version Info