Exports
[<Class>]
type Exports =
static member assert: Assert
static member describe: Suite
static member it: Test
static member mock: MockTracker
static member snapshot: Snapshot
static member suite: Suite
static member test: Test
static member MockPropertyContext<'PropertyType> () : MockPropertyContext<'PropertyType>
static member after (?fn: HookFn, ?options: HookOptions) : unit
static member afterEach (?fn: HookFn, ?options: HookOptions) : unit
static member before (?fn: HookFn, ?options: HookOptions) : unit
static member beforeEach (?fn: HookFn, ?options: HookOptions) : unit
static member only (?fn: TestFn) : Promise<unit>
static member only (?options: TestOptions, ?fn: TestFn) : Promise<unit>
static member only (?name: string, ?fn: TestFn) : Promise<unit>
static member only (?name: string, ?options: TestOptions, ?fn: TestFn) : Promise<unit>
static member run (?options: RunOptions) : TestsStream
static member skip (?fn: TestFn) : Promise<unit>
static member skip (?options: TestOptions, ?fn: TestFn) : Promise<unit>
static member skip (?name: string, ?fn: TestFn) : Promise<unit>
static member skip (?name: string, ?options: TestOptions, ?fn: TestFn) : Promise<unit>
static member todo (?fn: TestFn) : Promise<unit>
static member todo (?options: TestOptions, ?fn: TestFn) : Promise<unit>
static member todo (?name: string, ?fn: TestFn) : Promise<unit>
static member todo (?name: string, ?options: TestOptions, ?fn: TestFn) : Promise<unit>| Assembly | Xantham.Fable.Node |
| Attributes | [<Erase>] |
The package's value exports, each bound to its import.
Properties
static member assert: Assert
static member assert: AssertAn object whose methods are used to configure available assertions on the TestContext objects in the current process. The methods from node:assert and snapshot testing functions are available by default.
It is possible to apply the same configuration to all files by placing common configuration code in a module preloaded with --require or --import.
@since v22.14.0
static member describe: Suite
static member describe: SuiteThe suite() function is imported from the node:test module.
@since v20.13.0
| Parameter | |
|---|---|
name | The name of the suite, which is displayed when reporting test results. Defaults to the name property of fn, or '<anonymous>' if fn does not have a name. |
options | Configuration options for the suite. This supports the same options as {@link test}. |
fn | The suite function declaring nested tests and suites. The first argument to this function is a {@link SuiteContext} object. |
Returns. Immediately fulfilled with undefined.
static member it: Test
static member it: TestThe test() function is the value imported from the test module. Each invocation of this function results in reporting the test to the TestsStream.
The TestContext object passed to the fn argument can be used to perform actions related to the current test. Examples include skipping the test, adding additional diagnostic information, or creating subtests.
test() returns a Promise that fulfills once the test completes. if test() is called within a suite, it fulfills immediately. The return value can usually be discarded for top level tests. However, the return value from subtests should be used to prevent the parent test from finishing first and cancelling the subtest as shown in the following example.
test('top level test', async (t) => {
// The setTimeout() in the following subtest would cause it to outlive its
// parent test if 'await' is removed on the next line. Once the parent test
// completes, it will cancel any outstanding subtests.
await t.test('longer running subtest', async (t) => {
return new Promise((resolve, reject) => {
setTimeout(resolve, 1000);
});
});
});
The timeout option can be used to fail the test if it takes longer than timeout milliseconds to complete. However, it is not a reliable mechanism for canceling tests because a running test might block the application thread and thus prevent the scheduled cancellation.
@since v18.0.0, v16.17.0
| Parameter | |
|---|---|
name | The name of the test, which is displayed when reporting test results. Defaults to the name property of fn, or '<anonymous>' if fn does not have a name. |
options | Configuration options for the test. |
fn | The function under 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. |
Returns. Fulfilled with undefined once the test completes, or immediately if the test runs within a suite.
static member suite: Suite
static member suite: SuiteThe suite() function is imported from the node:test module.
@since v20.13.0
| Parameter | |
|---|---|
name | The name of the suite, which is displayed when reporting test results. Defaults to the name property of fn, or '<anonymous>' if fn does not have a name. |
options | Configuration options for the suite. This supports the same options as {@link test}. |
fn | The suite function declaring nested tests and suites. The first argument to this function is a {@link SuiteContext} object. |
Returns. Immediately fulfilled with undefined.
static member test: Test
static member test: TestThe test() function is the value imported from the test module. Each invocation of this function results in reporting the test to the TestsStream.
The TestContext object passed to the fn argument can be used to perform actions related to the current test. Examples include skipping the test, adding additional diagnostic information, or creating subtests.
test() returns a Promise that fulfills once the test completes. if test() is called within a suite, it fulfills immediately. The return value can usually be discarded for top level tests. However, the return value from subtests should be used to prevent the parent test from finishing first and cancelling the subtest as shown in the following example.
test('top level test', async (t) => {
// The setTimeout() in the following subtest would cause it to outlive its
// parent test if 'await' is removed on the next line. Once the parent test
// completes, it will cancel any outstanding subtests.
await t.test('longer running subtest', async (t) => {
return new Promise((resolve, reject) => {
setTimeout(resolve, 1000);
});
});
});
The timeout option can be used to fail the test if it takes longer than timeout milliseconds to complete. However, it is not a reliable mechanism for canceling tests because a running test might block the application thread and thus prevent the scheduled cancellation.
@since v18.0.0, v16.17.0
| Parameter | |
|---|---|
name | The name of the test, which is displayed when reporting test results. Defaults to the name property of fn, or '<anonymous>' if fn does not have a name. |
options | Configuration options for the test. |
fn | The function under 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. |
Returns. Fulfilled with undefined once the test completes, or immediately if the test runs within a suite.
Methods
static member MockPropertyContext<'PropertyType> () : MockPropertyContext<'PropertyType>
static member MockPropertyContext<'PropertyType> () : MockPropertyContext<'PropertyType>@since v22.20.0
static member after (?fn: HookFn, ?options: HookOptions) : unit
static member after (?fn: HookFn, ?options: HookOptions) : unitThis function creates a hook that runs after executing a suite.
describe('tests', async () => {
after(() => console.log('finished running tests'));
it('is a subtest', () => {
assert.ok('some relevant assertion here');
});
});
@since v18.8.0, v16.18.0
| Parameter | |
|---|---|
fn | The hook function. If the hook uses callbacks, the callback function is passed as the second argument. |
options | Configuration options for the hook. |
static member afterEach (?fn: HookFn, ?options: HookOptions) : unit
static member afterEach (?fn: HookFn, ?options: HookOptions) : unitThis function creates a hook that runs after each test in the current suite. The afterEach() hook is run even if the test fails.
describe('tests', async () => {
afterEach(() => console.log('finished running a test'));
it('is a subtest', () => {
assert.ok('some relevant assertion here');
});
});
@since v18.8.0, v16.18.0
| Parameter | |
|---|---|
fn | The hook function. If the hook uses callbacks, the callback function is passed as the second argument. |
options | Configuration options for the hook. |
static member before (?fn: HookFn, ?options: HookOptions) : unit
static member before (?fn: HookFn, ?options: HookOptions) : unitThis function creates a hook that runs before executing a suite.
describe('tests', async () => {
before(() => console.log('about to run some test'));
it('is a subtest', () => {
assert.ok('some relevant assertion here');
});
});
@since v18.8.0, v16.18.0
| Parameter | |
|---|---|
fn | The hook function. If the hook uses callbacks, the callback function is passed as the second argument. |
options | Configuration options for the hook. |
static member beforeEach (?fn: HookFn, ?options: HookOptions) : unit
static member beforeEach (?fn: HookFn, ?options: HookOptions) : unitThis function creates a hook that runs before each test in the current suite.
describe('tests', async () => {
beforeEach(() => console.log('about to run a test'));
it('is a subtest', () => {
assert.ok('some relevant assertion here');
});
});
@since v18.8.0, v16.18.0
| Parameter | |
|---|---|
fn | The hook function. If the hook uses callbacks, the callback function is passed as the second argument. |
options | Configuration options for the hook. |
static member only (?fn: TestFn) : Promise<unit>
static member only (?fn: TestFn) : Promise<unit>Shorthand for marking a test as only. This is the same as calling test with options.only set to true.
@since v20.2.0
static member only (?options: TestOptions, ?fn: TestFn) : Promise<unit>
static member only (?options: TestOptions, ?fn: TestFn) : Promise<unit>Shorthand for marking a test as only. This is the same as calling test with options.only set to true.
@since v20.2.0
static member only (?name: string, ?fn: TestFn) : Promise<unit>
static member only (?name: string, ?fn: TestFn) : Promise<unit>Shorthand for marking a test as only. This is the same as calling test with options.only set to true.
@since v20.2.0
static member only (?name: string, ?options: TestOptions, ?fn: TestFn) : Promise<unit>
static member only (?name: string, ?options: TestOptions, ?fn: TestFn) : Promise<unit>Shorthand for marking a test as only. This is the same as calling test with options.only set to true.
@since v20.2.0
static member run (?options: RunOptions) : TestsStream
static member run (?options: RunOptions) : TestsStreamNote: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.
import { tap } from 'node:test/reporters';
import { run } from 'node:test';
import process from 'node:process';
import path from 'node:path';
run({ files: [path.resolve('./tests/test.js')] })
.compose(tap)
.pipe(process.stdout);
@since v18.9.0, v16.19.0
| Parameter | |
|---|---|
options | Configuration options for running tests. |
static member skip (?fn: TestFn) : Promise<unit>
static member skip (?fn: TestFn) : Promise<unit>Shorthand for skipping a test. This is the same as calling test with options.skip set to true.
@since v20.2.0
static member skip (?options: TestOptions, ?fn: TestFn) : Promise<unit>
static member skip (?options: TestOptions, ?fn: TestFn) : Promise<unit>Shorthand for skipping a test. This is the same as calling test with options.skip set to true.
@since v20.2.0
static member skip (?name: string, ?fn: TestFn) : Promise<unit>
static member skip (?name: string, ?fn: TestFn) : Promise<unit>Shorthand for skipping a test. This is the same as calling test with options.skip set to true.
@since v20.2.0
static member skip (?name: string, ?options: TestOptions, ?fn: TestFn) : Promise<unit>
static member skip (?name: string, ?options: TestOptions, ?fn: TestFn) : Promise<unit>Shorthand for skipping a test. This is the same as calling test with options.skip set to true.
@since v20.2.0
static member todo (?fn: TestFn) : Promise<unit>
static member todo (?fn: TestFn) : Promise<unit>Shorthand for marking a test as TODO. This is the same as calling test with options.todo set to true.
@since v20.2.0
static member todo (?options: TestOptions, ?fn: TestFn) : Promise<unit>
static member todo (?options: TestOptions, ?fn: TestFn) : Promise<unit>Shorthand for marking a test as TODO. This is the same as calling test with options.todo set to true.
@since v20.2.0