Skip to content
// EFFECT DAYS 2026

TestFiles unstable

A fake HtmlFiles.Files for whole-app tests, so a test decides what the user chooses in each file picker, and inspects download requests, without a document, in Node too.

Provide layer next to TestHost.layer(). Every pick stays pending until choose or dismiss settles it. Run TestHost.settle after it to see the update. downloads returns the files requested for download.

Example Choosing a file in a whole-app test

import { UiSchema } from "effect/ui"
import { Html, HtmlFiles } from "effect/ui/html"
import { TestFiles } from "effect/ui/html/testing"
import { TestHost } from "effect/ui/testing"
import { Effect, Layer, Schema } from "effect"
const Message = UiSchema.TaggedEnum({
ClickedAttach: {},
Picked: { names: Schema.Array(Schema.String) }
})
const Attach = Html.component({
name: "Attach",
model: Schema.Array(Schema.String),
message: Message
}).make({
init: () => [],
update: {
ClickedAttach: ($) =>
$.run(HtmlFiles.pick(({ files }) => Message.Picked({ names: files.map((file) => file.name) }))),
Picked: (_, { names }) => names
},
view: (h, names) => h.button.on("click", Message.ClickedAttach()).children(names.join(", ") || "Attach")
})
Effect.gen(function*() {
const root = yield* TestHost.mount(Attach, {})
root.send(Message.ClickedAttach())
yield* TestHost.settle
yield* TestFiles.choose([new File(["hi"], "notes.txt")])
yield* TestHost.settle
root.model() // => ["notes.txt"]
}).pipe(Effect.provide(Layer.merge(TestHost.layer(), TestFiles.layer)), Effect.scoped, Effect.runPromise)
7 exports Since v4.2.0 Source

Constructors

make

unstable
Since v4.2.0

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

Signature

declare function make(): Files & TestFiles

Layers

layer

unstable
Since v4.2.0

Provides a fake HtmlFiles.Files with its control, TestFiles.

Signature

declare const layer: Layer.Layer<TestFiles>

Services

TestFiles

unstable
Since v4.2.0

The TestFiles service.

Signature

declare const TestFiles: Service<TestFiles, TestFiles>

TestFiles

interface unstable
Since v4.2.0

The TestFiles service: the fake's control.

Signature

interface TestFiles {
readonly downloads: () => readonly Array<File>;
readonly pending: () => readonly Array<PickOptions>;
readonly settle: (picked: Picked) => void;
}

Testing

choose

unstable
Since v4.2.0

Settles the pending picks with files, as the user choosing them.

Signature

declare function choose(files: readonly Array<File>): Effect<void, never, TestFiles>

dismiss

unstable
Since v4.2.0

Settles the pending picks with no files, as the user dismissing the picker.

Signature

declare const dismiss: Effect.Effect<void, never, TestFiles>

downloads

unstable
Since v4.2.0

Files requested for download, oldest first. No browser download occurs.

Signature

declare const downloads: Effect.Effect<ReadonlyArray<File>, never, TestFiles>