Skip to main content
Module

x/valtio/tests/snapshot.test.ts

πŸ’Š Valtio makes proxy-state simple for React and Vanilla
Go to Latest
File
import { proxy, snapshot } from 'valtio'
const sleep = (ms: number) => new Promise((resolve) => { setTimeout(resolve, ms) })
it('getter returns value after promise is resolved', async () => { const state = proxy<any>({ status: sleep(10).then(() => 'done') }) const snap = snapshot(state)
await new Promise((resolve) => { resolve(snap.status) }) .catch((thrown) => { expect(thrown).toBeInstanceOf(Promise) return thrown }) .then((value) => { expect(value).toBe('done') expect(snap.status).toBe('done') })})