/** * effract dogfoods its own testing package: the same behaviours pinned elsewhere * with hand-rolled createRoot/act, expressed through `@tmonier/effract-test`'s * `renderRec`. If the helpers regress, this fails. */ import { describe, expect, it } from 'vitest'; import * as Context from 'effect/Context'; import * as Effect from 'effect/Effect'; import * as Layer from 'effect/Layer'; import { renderRec } from '@tmonier/effract-test'; import { atom, mount, query, rec } from '../../index.client.ts'; class Store extends Context.Service()('test/DogfoodStore', { make: Effect.sync(() => { const n = atom('n', 0); return { n, inc: () => n.update((x) => x + 1) }; }), }) { static readonly layer = Layer.effect(Store, Store.make); } describe('renderRec dogfood', () => { it('drives an atom-backed REC through an event', async () => { const View = rec(function* () { const store = yield* Store; const n = yield* store.n; return ( ); }); const r = await renderRec(mount(Store.layer, View)); expect(r.text()).toBe('0'); await r.click('[data-x="b"]'); expect(r.text()).toBe('1'); await r.unmount(); }); it('resolves a query through Suspense', async () => { const View = rec(function* () { const value = yield* query(Effect.succeed('hi')); return {value}; }).suspense(loading); const r = await renderRec(mount(Layer.empty, View)); await r.flush(); expect(r.text()).toContain('hi'); await r.unmount(); }); });