Skip to content
// EFFECT DAYS 2026

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)
5 exports Since v4.2.0 Source

Constructors

make

unstable
Since v4.2.0

Makes a fake source and its control, with its clock at 0. layer provides a new one per build.

Signature

declare function make(): AnimationFrames & TestAnimationFrames

Layers

layer

unstable
Since v4.2.0

Provides a fake HtmlSubscription.AnimationFrames with its control, TestAnimationFrames.

Signature

declare const layer: Layer.Layer<TestAnimationFrames>

Services

Since v4.2.0

The TestAnimationFrames service.

Signature

declare const TestAnimationFrames: Service<TestAnimationFrames, TestAnimationFrames>

TestAnimationFrames

interface unstable
Since v4.2.0

The TestAnimationFrames service: the fake's control.

Signature

interface TestAnimationFrames {
readonly fire: (delta?: number) => void;
}

Testing

fire

unstable
Since v4.2.0

Fires a frame delta ms after the last, 16 by default, through the fake.

Signature

declare function fire(delta?: number): Effect<void, never, TestAnimationFrames>