TestContext

external class TestContext(source)

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.

Since

v18.0.0, v16.17.0

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

An object containing assertion methods bound to the test context. The top-level functions from the node:assert module are exposed here for the purpose of creating test plans.

Link copied to clipboard

The name of the test and each of its ancestors, separated by >.

Link copied to clipboard

Each test provides its own MockTracker instance.

Link copied to clipboard

The name of the test.

Link copied to clipboard
Link copied to clipboard
var test: Any?

This function is used to create subtests under the current test. This function behaves in the same fashion as the top level {@link test} function.

Functions

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

This function is used to create a hook that runs after the current test finishes.

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

This function is used to create a hook running after each subtest of the current test.

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

This function is used to create a hook running before subtest of the current test.

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

This function is used to create a hook running before each subtest of the current test.

Link copied to clipboard
fun diagnostic(message: String)

This function is used to write diagnostics to the output. Any diagnostic information is included at the end of the test's results. This function does not return a value.

Link copied to clipboard
fun plan(count: Number)

Used to set the number of assertions and subtests that are expected to run within the test. If the number of assertions and subtests that run does not match the expected count, the test will fail.

Link copied to clipboard
fun runOnly(shouldRunOnlyTests: Boolean)

If shouldRunOnlyTests is truthy, the test context will only run tests that have the only option set. Otherwise, all tests are run. If Node.js was not started with the --test-only command-line option, this function is a no-op.

Link copied to clipboard
fun skip(message: String = definedExternally)

This function causes the test's output to indicate the test as skipped. If message is provided, it is included in the output. Calling skip() does not terminate execution of the test function. This function does not return a value.

Link copied to clipboard
fun todo(message: String = definedExternally)

This function adds a TODO directive to the test's output. If message is provided, it is included in the output. Calling todo() does not terminate execution of the test function. This function does not return a value.