TestAnimationFrames unstable
A fake HtmlSubscription.AnimationFrames for whole-app tests, so a test
fires animation frames without a window, in Node too.
Provide layer next to TestHost.layer(), and fire a frame with
fire, giving the time since the last one. Every onAnimationFrame
of the mounted components runs. Run TestHost.settle after it to see
the update.
Example Two frames in a whole-app test
import { UiSchema } from "effect/ui"import { Html, HtmlSubscription } from "effect/ui/html"import { TestAnimationFrames } from "effect/ui/html/testing"import { TestHost } from "effect/ui/testing"import { Effect, Layer, Schema } from "effect"
const Message = UiSchema.TaggedEnum({ TickedFrame: { delta: Schema.Number } })
const Clock = Html.component({ name: "Clock", model: Schema.Number, message: Message}).make({ init: () => 0, update: { TickedFrame: ($, { delta }) => $.model + delta }, view: (h, elapsed) => h.p(String(elapsed)), subscriptions: () => [HtmlSubscription.onAnimationFrame((delta) => Message.TickedFrame({ delta }))]})
Effect.gen(function*() { const root = yield* TestHost.mount(Clock, {}) yield* TestHost.settle yield* TestAnimationFrames.fire(16) yield* TestAnimationFrames.fire(17) yield* TestHost.settle root.model() // => 33}).pipe(Effect.provide(Layer.merge(TestHost.layer(), TestAnimationFrames.layer)), Effect.scoped, Effect.runPromise)Constructors
Layers
Services
TestAnimationFrames
unstable Since v4.2.0 Source
The TestAnimationFrames service.
Signature
declare const TestAnimationFrames: Service<TestAnimationFrames, TestAnimationFrames> Since v4.2.0 Source
The TestAnimationFrames service: the fake's control.
Signature
interface TestAnimationFrames { readonly fire: (delta?: number) => void;}