Vitest
Vitest integrates well with the vite bundler and provides a fast and reliable testing framework for unit as well as component tests. There are even options to integrate Vitest with Storybook.
The bindings for the Vitest ecosystem are developed and maintained by the Fable Hub and used for testing in the Feliz project.
Vitest 5 requires Node.js 22.12 or newer and Vite 6.4 or newer. Install a compatible vite alongside vitest in applications, and pass --config explicitly when the Vitest config lives above the directory where the test command runs.
The Feliz template also ships with Vitest preconfigured. You can get started with Vitest right away when creating a new Feliz project using the template.
describe "FragmentComponent" <| fun _ ->
testPromise "renders multiple elements from a fragment" <| fun _ -> promise {
RTL.render (Components.FragmentComponent())
|> ignore
let first = RTL.screen.getByTestId "first"
let second = RTL.screen.getByTestId "second"
expect(first).toHaveTextContent "Hello"
expect(second).toHaveTextContent "World"
}
For data-driven tests, test.for keeps each F# record as one typed case. A mock callback can be created without an implementation:
(Vitest.Test.forCases [|
{| input = 1; expected = 2 |}
{| input = 4; expected = 5 |}
|]).run("increments $input to $expected", fun case ->
Vitest.expect(case.input + 1).toBe(case.expected)
)
let callback = Vitest.vi.fn<int, unit>()
callback 42
Vitest.expect(callback).toHaveBeenCalledWith([| box 42 |])