Skip to content

Commit

Permalink
add tests: atoms accessed with write get should have their dependenci…
Browse files Browse the repository at this point in the history
…es updated
  • Loading branch information
dmaskasky committed Nov 17, 2024
1 parent 29662ea commit c18be07
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/vanilla/dependency.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, it, vi } from 'vitest'
import { atom, createStore } from 'jotai/vanilla'
import type { Getter } from 'jotai/vanilla'

it('can propagate updates with async atom chains', async () => {
const store = createStore()
Expand Down Expand Up @@ -334,3 +335,15 @@ it('handles complex dependency chains', async () => {
resolve()
expect(await promise2).toBe(10)
})

it('can read sync derived atom in write without initializing', () => {
const store = createStore()
const a = atom(0)
const b = atom((get) => get(a) + 1)
const c = atom(null, (get, set) => set(a, get(b)))
store.set(c)
expect(store.get(a)).toBe(1)
store.set(c)
// note: this is why write get needs to update deps
expect(store.get(a)).toBe(2)
})

0 comments on commit c18be07

Please sign in to comment.