Skip to content

Commit

Permalink
add tests: can read sync derived atom in write without initializing (#…
Browse files Browse the repository at this point in the history
…2824)

* add tests: atoms accessed with write get should have their dependencies updated

* Update tests/vanilla/dependency.test.tsx

---------

Co-authored-by: Daishi Kato <[email protected]>
  • Loading branch information
dmaskasky and dai-shi authored Nov 17, 2024
1 parent 29662ea commit 1bf91ce
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/vanilla/dependency.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,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 1bf91ce

Please sign in to comment.