Skip to content

remix/test · Interface

View Source

TestContext

Summary

Test Context providing utilities for the Remix test runner. The context is passed as the first argument to the test/it functions.

Signature

interface TestContext {
  mock: { fn: any; method: any }
  signal: AbortSignal
  after(fn: () => void): void
  serve(server: TestServer): Promise<Page>
  useFakeTimers(): FakeTimers
}

Properties

mock

Function mocks and method spies using mock, restored automatically after the test. Mock restoration and test cleanup callbacks run in registration order, even after failures.

signal

An abort signal for the current test. The signal is aborted when the test times out or when a user-provided test signal aborts.

Methods

after(fn: () => void): void

Registers a cleanup function to be called after the test completes.

Parameters

fn

The cleanup function to execute

serve(server: TestServer): Promise<Page>

Wires a running test server up to a Playwright page so the test can drive it. The server is closed automatically when the test ends. Pair with createTestServer from @remix-run/node-fetch-server/test to spin up the server.

Parameters

server

The running server the page should target

useFakeTimers(): FakeTimers

Activates fake timers for testing time-dependent code.