Repository F# setup
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Layers
open Axial.Console
open Axial.FileSystem
open Axial.Hosting
open Axial.Hosting.Browser
open Axial.Hosting.Node
open Axial.PlatformService
open Axial.State
open Axial.Telemetry
open Axial.Telemetry.JavaScript

Testing

Supply fake environment values or replace layers at the execution boundary. Public examples use the same workflow shape as production code.

A first test is a fake environment record, one Flow.run, and one assertion — no HTTP or layers required:

Show page setup
// Setup for the checked example on this page.
open Axial
/// Fails the docs test when an example's result differs from the value shown.
let shouldEqual expected actual =
    if actual <> expected then failwithf "Expected %A but got %A" expected actual
Verified
type UserLookup = { FindName: int -> string }

type UserEnv = { Lookup: UserLookup }

let findUserName (id: int) : Flow<UserEnv, Never, string> =
    Flow.envWith (fun env -> env.Lookup.FindName id)

// The test supplies a fake environment; production supplies the real lookup.
let fakeEnv = { Lookup = { FindName = fun id -> if id = 42 then "Ada" else "unknown" } }
Verified
findUserName 42 |> Flow.run fakeEnv |> shouldEqual (Exit.Success "Ada" : Exit<string, Never>)
findUserName 1 |> Flow.run fakeEnv |> shouldEqual (Exit.Success "unknown" : Exit<string, Never>)