Package-level declarations

Types

Link copied to clipboard
sealed external interface AssertSnapshotOptions
Link copied to clipboard
sealed external interface DiagnosticData : TestLocationInfo
Link copied to clipboard
typealias HookFn = (c: Any, done: (result: Any?) -> Unit) -> Any?

The hook function. The first argument is the context in which the hook is called. If the hook uses callbacks, the callback function is passed as the second argument.

Link copied to clipboard
sealed external interface HookOptions

Configuration options for hooks.

Link copied to clipboard
sealed external interface Mock<F : Function<*>>
Link copied to clipboard
sealed external interface MockFunctionCall<F : Function<*>, ReturnType, Args>
Link copied to clipboard
external class MockFunctionContext<F : Function<*>>

The MockFunctionContext class is used to inspect or manipulate the behavior of mocks created via the MockTracker APIs.

Link copied to clipboard
sealed external interface MockFunctionOptions
Link copied to clipboard
sealed external interface MockMethodOptions : MockFunctionOptions
Link copied to clipboard
external class MockModuleContext
Link copied to clipboard
sealed external interface MockModuleOptions
Link copied to clipboard
external class MockTimers

Mocking timers is a technique commonly used in software testing to simulate and control the behavior of timers, such as setInterval and setTimeout, without actually waiting for the specified time intervals.

Link copied to clipboard
sealed external interface MockTimersOptions
Link copied to clipboard
external class MockTracker

The MockTracker class is used to manage mocking functionality. The test runner module provides a top level mock export which is a MockTracker instance. Each test also provides its own MockTracker instance via the test context's mock property.

Link copied to clipboard
Link copied to clipboard
sealed external interface RunOptions
Link copied to clipboard
external class SuiteContext

An instance of SuiteContext is passed to each suite function in order to interact with the test runner. However, the SuiteContext constructor is not exposed as part of the API.

Link copied to clipboard
typealias SuiteFn = (s: SuiteContext) -> PromiseResult<Void>

The type of a suite test function. The argument to this function is a {@link SuiteContext} object.

Link copied to clipboard
sealed external interface TestComplete : TestLocationInfo
Link copied to clipboard
sealed external interface TestCompleteDetails
Link copied to clipboard
external class TestContext

An instance of TestContext is passed to each test function in order to interact with the test runner. However, the TestContext constructor is not exposed as part of the API.

Link copied to clipboard
sealed external interface TestContextAssert
Link copied to clipboard
typealias TestContextHookFn = (t: TestContext, done: (result: Any?) -> Unit) -> Any?

The hook function. The first argument is a TestContext object. If the hook uses callbacks, the callback function is passed as the second argument.

Link copied to clipboard
sealed external interface TestCoverage
Link copied to clipboard
sealed external interface TestCoverageSummary
Link copied to clipboard
sealed external interface TestCoverageSummaryFilesItem
Link copied to clipboard
Link copied to clipboard
sealed external interface TestCoverageSummaryFilesItemLinesItem
Link copied to clipboard
sealed external interface TestCoverageSummaryTotals
Link copied to clipboard
sealed external interface TestDequeue : TestLocationInfo
Link copied to clipboard
sealed external interface TestEnqueue : TestLocationInfo
Link copied to clipboard
sealed external interface TestError : Throwable
Link copied to clipboard
sealed external interface TestFail : TestLocationInfo
Link copied to clipboard
sealed external interface TestFailDetails
Link copied to clipboard
typealias TestFn = (t: TestContext, done: (result: Any?) -> Unit) -> PromiseResult<Void>

The type of a function passed to {@link test}. The first argument to this function is a {@link TestContext} object. If the test uses callbacks, the callback function is passed as the second argument.

Link copied to clipboard
sealed external interface TestLocationInfo
Link copied to clipboard
sealed external interface TestOptions
Link copied to clipboard
sealed external interface TestPass : TestLocationInfo
Link copied to clipboard
sealed external interface TestPassDetails
Link copied to clipboard
sealed external interface TestPlan : TestLocationInfo
Link copied to clipboard
sealed external interface TestShard
Link copied to clipboard

A successful call to run() will return a new TestsStream object, streaming a series of events representing the execution of the tests.

Link copied to clipboard
sealed external interface TestsStreamEvent
Link copied to clipboard
sealed external interface TestStart : TestLocationInfo
Link copied to clipboard
sealed external interface TestStderr
Link copied to clipboard
sealed external interface TestStdout
Link copied to clipboard
sealed external interface Timer

Properties

Link copied to clipboard
external val mock: MockTracker

Functions

Link copied to clipboard
external fun after(fn: HookFn = definedExternally, options: HookOptions = definedExternally)

This function creates a hook that runs after executing a suite.

Link copied to clipboard
external fun afterEach(fn: HookFn = definedExternally, options: HookOptions = definedExternally)

This function creates a hook that runs after each test in the current suite. The afterEach() hook is run even if the test fails.

Link copied to clipboard
external fun before(fn: HookFn = definedExternally, options: HookOptions = definedExternally)

This function creates a hook that runs before executing a suite.

Link copied to clipboard
external fun beforeEach(fn: HookFn = definedExternally, options: HookOptions = definedExternally)

This function creates a hook that runs before each test in the current suite.

Link copied to clipboard
suspend fun describe(fn: SuiteFn = undefined.unsafeCast<Nothing>()): Void
suspend fun describe(name: String = undefined.unsafeCast<Nothing>(), fn: SuiteFn = undefined.unsafeCast<Nothing>()): Void
suspend fun describe(options: TestOptions = undefined.unsafeCast<Nothing>(), fn: SuiteFn = undefined.unsafeCast<Nothing>()): Void
suspend fun describe(name: String = undefined.unsafeCast<Nothing>(), options: TestOptions = undefined.unsafeCast<Nothing>(), fn: SuiteFn = undefined.unsafeCast<Nothing>()): Void
Link copied to clipboard
external fun describeAsync(): Promise<Void>
external fun describeAsync(fn: SuiteFn = definedExternally): Promise<Void>
external fun describeAsync(name: String = definedExternally, fn: SuiteFn = definedExternally): Promise<Void>
external fun describeAsync(options: TestOptions = definedExternally, fn: SuiteFn = definedExternally): Promise<Void>

external fun describeAsync(name: String = definedExternally, options: TestOptions = definedExternally, fn: SuiteFn = definedExternally): Promise<Void>

Alias for {@link suite}.

Link copied to clipboard
suspend fun it(fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun it(name: String = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun it(options: TestOptions = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun it(name: String = undefined.unsafeCast<Nothing>(), options: TestOptions = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
Link copied to clipboard
external fun itAsync(): Promise<Void>
external fun itAsync(fn: TestFn = definedExternally): Promise<Void>
external fun itAsync(name: String = definedExternally, fn: TestFn = definedExternally): Promise<Void>
external fun itAsync(options: TestOptions = definedExternally, fn: TestFn = definedExternally): Promise<Void>

external fun itAsync(name: String = definedExternally, options: TestOptions = definedExternally, fn: TestFn = definedExternally): Promise<Void>

Alias for {@link test}.

Link copied to clipboard
suspend fun only(): Void
suspend fun only(fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun only(name: String = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun only(options: TestOptions = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun only(name: String = undefined.unsafeCast<Nothing>(), options: TestOptions = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
Link copied to clipboard
external fun onlyAsync(): Promise<Void>
external fun onlyAsync(fn: TestFn = definedExternally): Promise<Void>
external fun onlyAsync(name: String = definedExternally, fn: TestFn = definedExternally): Promise<Void>
external fun onlyAsync(options: TestOptions = definedExternally, fn: TestFn = definedExternally): Promise<Void>

external fun onlyAsync(name: String = definedExternally, options: TestOptions = definedExternally, fn: TestFn = definedExternally): Promise<Void>

Shorthand for marking a test as only. This is the same as calling {@link test} with options.only set to true.

Link copied to clipboard
external fun run(options: RunOptions = definedExternally): TestsStream

Note: shard is used to horizontally parallelize test running across machines or processes, ideal for large-scale executions across varied environments. It's incompatible with watch mode, tailored for rapid code iteration by automatically rerunning tests on file changes.

Link copied to clipboard
suspend fun skip(): Void
suspend fun skip(fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun skip(name: String = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun skip(options: TestOptions = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun skip(name: String = undefined.unsafeCast<Nothing>(), options: TestOptions = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
Link copied to clipboard
external fun skipAsync(): Promise<Void>
external fun skipAsync(fn: TestFn = definedExternally): Promise<Void>
external fun skipAsync(name: String = definedExternally, fn: TestFn = definedExternally): Promise<Void>
external fun skipAsync(options: TestOptions = definedExternally, fn: TestFn = definedExternally): Promise<Void>

external fun skipAsync(name: String = definedExternally, options: TestOptions = definedExternally, fn: TestFn = definedExternally): Promise<Void>

Shorthand for skipping a test. This is the same as calling {@link test} with options.skip set to true.

Link copied to clipboard
suspend fun suite(fn: SuiteFn = undefined.unsafeCast<Nothing>()): Void
suspend fun suite(name: String = undefined.unsafeCast<Nothing>(), fn: SuiteFn = undefined.unsafeCast<Nothing>()): Void
suspend fun suite(options: TestOptions = undefined.unsafeCast<Nothing>(), fn: SuiteFn = undefined.unsafeCast<Nothing>()): Void
suspend fun suite(name: String = undefined.unsafeCast<Nothing>(), options: TestOptions = undefined.unsafeCast<Nothing>(), fn: SuiteFn = undefined.unsafeCast<Nothing>()): Void
Link copied to clipboard
external fun suiteAsync(): Promise<Void>
external fun suiteAsync(fn: SuiteFn = definedExternally): Promise<Void>
external fun suiteAsync(name: String = definedExternally, fn: SuiteFn = definedExternally): Promise<Void>
external fun suiteAsync(options: TestOptions = definedExternally, fn: SuiteFn = definedExternally): Promise<Void>

external fun suiteAsync(name: String = definedExternally, options: TestOptions = definedExternally, fn: SuiteFn = definedExternally): Promise<Void>

The suite() function is imported from the node:test module.

Link copied to clipboard
suspend fun test(): Void
suspend fun test(fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun test(name: String = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun test(options: TestOptions = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun test(name: String = undefined.unsafeCast<Nothing>(), options: TestOptions = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
Link copied to clipboard
external fun testAsync(): Promise<Void>
external fun testAsync(fn: TestFn = definedExternally): Promise<Void>
external fun testAsync(options: TestOptions = definedExternally, fn: TestFn = definedExternally): Promise<Void>
external fun testAsync(name: String = definedExternally, options: TestOptions = definedExternally, fn: TestFn = definedExternally): Promise<Void>

external fun testAsync(name: String = definedExternally, fn: TestFn = definedExternally): Promise<Void>

The test() function is the value imported from the test module. Each invocation of this function results in reporting the test to the TestsStream.

Link copied to clipboard
suspend fun todo(): Void
suspend fun todo(fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun todo(name: String = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun todo(options: TestOptions = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
suspend fun todo(name: String = undefined.unsafeCast<Nothing>(), options: TestOptions = undefined.unsafeCast<Nothing>(), fn: TestFn = undefined.unsafeCast<Nothing>()): Void
Link copied to clipboard
external fun todoAsync(): Promise<Void>
external fun todoAsync(fn: TestFn = definedExternally): Promise<Void>
external fun todoAsync(name: String = definedExternally, fn: TestFn = definedExternally): Promise<Void>
external fun todoAsync(options: TestOptions = definedExternally, fn: TestFn = definedExternally): Promise<Void>

external fun todoAsync(name: String = definedExternally, options: TestOptions = definedExternally, fn: TestFn = definedExternally): Promise<Void>

Shorthand for marking a test as TODO. This is the same as calling {@link test} with options.todo set to true.