Skip to content

Commit

Permalink
test: should update dependents with the value of the unwrapped atom w…
Browse files Browse the repository at this point in the history
…hen the promise resolves
  • Loading branch information
dmaskasky committed Jan 8, 2025
1 parent 5ff8f63 commit fc05691
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/vanilla/utils/unwrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,17 @@ describe('unwrap', () => {
expect(store.get(syncAtom)).toEqual('concrete')
})
})

it('should update dependents with the value of the unwrapped atom when the promise resolves', async () => {
const store = createStore()
const asyncTarget = atom(() => Promise.resolve('value'))
const target = unwrap(asyncTarget)
const results: string[] = []
const derived = atom(async (get) => {
await Promise.resolve()
results.push('effect ' + get(target))
})
store.sub(derived, () => {})
await new Promise((r) => setTimeout(r))
expect(results).toEqual(['effect undefined', 'effect value'])
})

0 comments on commit fc05691

Please sign in to comment.