Skip to content
// EFFECT DAYS 2026

TestImages unstable

A fake HtmlImages.Images for whole-app tests, so a test decides how each image load settles, without a document, in Node too.

Provide layer next to TestHost.layer(). Every load stays pending until load or fail settles the loads of its source. Run TestHost.settle after it to see the update.

Example Loading a photo in a whole-app test

import { Subscription, UiSchema } from "effect/ui"
import { Html, HtmlImages } from "effect/ui/html"
import { TestImages } from "effect/ui/html/testing"
import { TestHost } from "effect/ui/testing"
import { Effect, Layer, Schema, Stream } from "effect"
const Message = UiSchema.TaggedEnum({ Settled: { status: Schema.Literals(["loaded", "error"]) } })
const Photo = Html.component({
name: "Photo",
model: Schema.String,
message: Message
}).make({
init: () => "loading",
update: { Settled: (_, { status }) => status },
view: (h, status) => h.p(status),
subscriptions: () => [
Subscription.make(
"photo",
Stream.fromEffect(HtmlImages.Images.use((images) => images.load({ src: "/ada.png" }))).pipe(
Stream.map((status) => Message.Settled({ status }))
)
)
]
})
Effect.gen(function*() {
const root = yield* TestHost.mount(Photo, {})
yield* TestHost.settle
yield* TestImages.load({ src: "/ada.png" })
yield* TestHost.settle
root.model() // => "loaded"
}).pipe(Effect.provide(Layer.merge(TestHost.layer(), TestImages.layer)), Effect.scoped, Effect.runPromise)
6 exports Since v4.2.0 Source

Constructors

make

unstable
Since v4.2.0

Makes a fake loader and its control. layer provides a new one per build.

Signature

declare function make(): Images & TestImages

Layers

layer

unstable
Since v4.2.0

Provides a fake HtmlImages.Images with its control, TestImages.

Signature

declare const layer: Layer.Layer<TestImages>

Services

TestImages

unstable
Since v4.2.0

The TestImages service.

Signature

declare const TestImages: Service<TestImages, TestImages>

TestImages

interface unstable
Since v4.2.0

The TestImages service: the fake's control.

Signature

interface TestImages {
readonly settle: (source: ImageSource, status: "error" | "loaded") => void;
}

Testing

fail

unstable
Since v4.2.0

Settles the pending loads of source as "error".

Signature

declare function fail(source: ImageSource): Effect<void, never, TestImages>

load

unstable
Since v4.2.0

Settles the pending loads of source as "loaded".

Signature

declare function load(source: ImageSource): Effect<void, never, TestImages>