|
1 | 1 | import { Suspense } from 'react'
|
2 | 2 | import { fireEvent, render, waitFor } from '@testing-library/react'
|
3 | 3 | import { useAtom } from 'jotai'
|
4 |
| -import { RESET, atomWithHash, atomWithStorage } from 'jotai/utils' |
| 4 | +import { |
| 5 | + RESET, |
| 6 | + atomWithHash, |
| 7 | + atomWithStorage, |
| 8 | + createJSONStorage, |
| 9 | +} from 'jotai/utils' |
5 | 10 | import { getTestProvider } from '../testUtils'
|
6 | 11 |
|
7 | 12 | const Provider = getTestProvider()
|
@@ -180,6 +185,36 @@ describe('atomWithStorage (async)', () => {
|
180 | 185 | })
|
181 | 186 | })
|
182 | 187 |
|
| 188 | +describe('atomWithStorage (no storage) (#949)', () => { |
| 189 | + it('can throw in createJSONStorage', async () => { |
| 190 | + const countAtom = atomWithStorage( |
| 191 | + 'count', |
| 192 | + 1, |
| 193 | + createJSONStorage(() => { |
| 194 | + throw new Error('no storage') |
| 195 | + }) |
| 196 | + ) |
| 197 | + |
| 198 | + const Counter = () => { |
| 199 | + const [count, setCount] = useAtom(countAtom) |
| 200 | + return ( |
| 201 | + <> |
| 202 | + <div>count: {count}</div> |
| 203 | + <button onClick={() => setCount((c) => c + 1)}>button</button> |
| 204 | + </> |
| 205 | + ) |
| 206 | + } |
| 207 | + |
| 208 | + const { findByText } = render( |
| 209 | + <Provider> |
| 210 | + <Counter /> |
| 211 | + </Provider> |
| 212 | + ) |
| 213 | + |
| 214 | + await findByText('count: 1') |
| 215 | + }) |
| 216 | +}) |
| 217 | + |
183 | 218 | describe('atomWithHash', () => {
|
184 | 219 | it('simple count', async () => {
|
185 | 220 | const countAtom = atomWithHash('count', 1)
|
|
0 commit comments