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)Constructors
Layers
Services
TestImages
unstable Since v4.2.0 Source
The TestImages service.
Signature
declare const TestImages: Service<TestImages, TestImages> Since v4.2.0 Source
The TestImages service: the fake's control.
Signature
interface TestImages { readonly settle: (source: ImageSource, status: "error" | "loaded") => void;}Testing
Settles the pending loads of source as "error".
Signature
declare function fail(source: ImageSource): Effect<void, never, TestImages>Settles the pending loads of source as "loaded".
Signature
declare function load(source: ImageSource): Effect<void, never, TestImages>