Skip to content

Commit 71d2fa0

Browse files
committed
test: add test for getStringStorage method from createJSONStorage to not be called in server
1 parent a1b1998 commit 71d2fa0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tests/react/vanilla-utils/atomWithStorage.test.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99
createJSONStorage,
1010
unstable_withStorageValidator as withStorageValidator,
1111
} from 'jotai/vanilla/utils'
12-
import type { SyncStringStorage } from 'jotai/vanilla/utils/atomWithStorage'
12+
import type {
13+
AsyncStringStorage,
14+
SyncStringStorage,
15+
} from 'jotai/vanilla/utils/atomWithStorage'
1316

1417
const resolve: (() => void)[] = []
1518

@@ -337,7 +340,7 @@ describe('atomWithStorage (in non-browser environment)', () => {
337340
const asyncStorageData: Record<string, string> = {
338341
count: '10',
339342
}
340-
const asyncDummyStorage = {
343+
const asyncDummyStorage: AsyncStringStorage = {
341344
getItem: async (key: string) => {
342345
await new Promise<void>((r) => resolve.push(r))
343346
return asyncStorageData[key] as string
@@ -367,6 +370,13 @@ describe('atomWithStorage (in non-browser environment)', () => {
367370

368371
expect(storage.subscribe).toBeUndefined()
369372
})
373+
374+
it('createJSONStorage with custom subscribe', async () => {
375+
const subscriber = vi.fn()
376+
createJSONStorage(subscriber)
377+
378+
expect(subscriber).not.toBeCalled()
379+
})
370380
})
371381

372382
describe('atomWithStorage (with browser storage)', () => {

0 commit comments

Comments
 (0)