Test
test defines a test case. It supports chainable modifiers and fixture extension for flexible and powerful test definitions.
Alias: it.
test
- Type:
(name: string, fn: (testContext: TestContext) => void | Promise<void>, timeout?: number) => void
Defines a test case.
test.only
Only run certain tests in a test file.
test.skip
Skips certain tests.
test.todo
Marks certain tests as todo.
test.each
- Type:
test.each(cases: ReadonlyArray<T>)(name: string, fn: (param: T) => void | Promise<void>, timeout?: number) => void
Runs the same test logic for each item in the provided array.
You can inject parameters with printf formatting in the test name in the order of the test function parameters.
%s: String%d: Number%i: Integer%f: Floating point value%j: JSON%o: Object%#: 0-based index of the test case%$: 1-based index of the test case%%: Single percent sign ('%')
You can also access object properties and array elements with $ prefix:
test.for
- Type:
test.for(cases: ReadonlyArray<T>)(name: string, fn: (param: T, testContext: TestContext) => void | Promise<void>, timeout?: number) => void
Alternative to test.each to provide TestContext.
test.fails
Marks the test as expected to fail.
test.concurrent
Runs the test concurrently with consecutive concurrent flags.
test.sequential
Runs the test sequentially (default behavior).
test.runIf
Runs the test only if the condition is true.
test.skipIf
Skips the test if the condition is true.
test.extend
- Type:
test.extend(fixtures: Fixtures)
Extends the test context with custom fixtures.
Chainable modifiers
test supports chainable modifiers, so you can use them together. For example:
test.only.runIf(condition)(ortest.runIf(condition).only) will only run the test block if the condition is true.test.skipIf(condition).concurrent(ortest.concurrent.skipIf(condition)) will skip the test block if the condition is true, otherwise run the tests concurrently.test.runIf(condition).concurrent(ortest.concurrent.runIf(condition)) will only run the test block concurrently if the condition is true.test.only.concurrent(ortest.concurrent.only) will only run the test block concurrently.test.for(cases).concurrent(ortest.concurrent.for(cases)) will run the test block concurrently for each case in the provided array.- ......
Types
TestContext
TestContext provides some APIs, context information, and custom fixtures related to the current test.
You can also extend TestContext with custom fixtures using test.extend.