velt/test
API referenceThe test runner, written in Velt, with Vitest's API; import ... from "vitest" imports this module too. velt test (Testing) compiles the test files into a program whose generated main registers their tests with this module and hands it control. For a walkthrough, read the guide.
Exports
actual.afterAllRuns fn once after the last test of the group (or file) that runs in this process; a group's afterAll hooks run last-registered first, as Vitest's.afterEachRuns fn after each test of the group (or file), inner groups' first, also after a failure; a group's afterEach hooks run last-registered first, as Vitest's.beforeAllRuns fn once before the first test of the group (or file) that runs in this process.beforeEachRuns fn before each test of the group (or file), outer groups' first.describeA group of tests: fn runs when the file's tests are collected, and the tests and hooks it registers belong to the group.itA test: fn, sync or async, passes unless it throws (or its promise rejects).testit.ExpectWhat expect(actual) returns: the matchers for actual.SettlesWhat a test or hook callback returns: nothing, or a promise, which is awaited.Re-exported from velt/test/expect
function expect<T>(actual: T): Expect<T>The matchers for actual.
Re-exported from velt/test/suite
function afterAll<R extends Settles>(fn: () => R throws unknown)Runs fn once after the last test of the group (or file) that runs in this process; a group's
afterAll hooks run last-registered first, as Vitest's.
Re-exported from velt/test/suite
function afterEach<R extends Settles>(fn: () => R throws unknown)Runs fn after each test of the group (or file), inner groups' first, also after a failure;
a group's afterEach hooks run last-registered first, as Vitest's.
Re-exported from velt/test/suite
function beforeAll<R extends Settles>(fn: () => R throws unknown)Runs fn once before the first test of the group (or file) that runs in this process.
Re-exported from velt/test/suite
function beforeEach<R extends Settles>(fn: () => R throws unknown)Runs fn before each test of the group (or file), outer groups' first.
Re-exported from velt/test/suite
function describe<R extends Settles>(
name: string,
fn: () => R throws unknown,
)A group of tests: fn runs when the file's tests are collected, and the tests and hooks it
registers belong to the group. If it throws (or is async), none of the group's tests run: a
test named as the group fails with the error.
Re-exported from velt/test/suite
function it<R extends Settles>(name: string, fn: () => R throws unknown)A test: fn, sync or async, passes unless it throws (or its promise rejects).
Re-exported from velt/test/suite
function test<R extends Settles>(name: string, fn: () => R throws unknown)it.
Re-exported from velt/test/expect
class Expect<T>What expect(actual) returns: the matchers for actual.
Returned byexpect
readonly actual: TThe value under test.
readonly negated: boolAfter .not: every matcher checks the opposite.
constructor(actual: T, negated: bool)No doc comment yetget not(): Expect<T>The same matchers, each checking the opposite.
check(pass: bool, message: string, notMessage?: string)Fails the test with message unless pass. After .not, fails if pass, with
notMessage (by default message with its first to written not to). Every matcher,
built-in or added with extend, checks through this.
toBe(expected: T)Object.is(actual, expected): the same value (NaN is NaN, 0 isn't -0).
toEqual(expected: T)Deep equality, as Vitest's: contents, recursively, class instances by their fields (a Date
by its time, a Set by its members in any order), numbers with Object.is (NaN equals
itself, 0 doesn't equal -0).
toBeNull()actual is null.
toBeUndefined()actual is undefined.
toBeDefined()actual is not undefined.
toBeTruthy()Boolean(actual) is true.
toBeFalsy()Boolean(actual) is false.
Re-exported from velt/test/suite
What a test or hook callback returns: nothing, or a promise, which is awaited. it's callback
returns a type with this bound, so a sync and an async callback both fit.
Used byafterAllafterEachbeforeAllbeforeEachdescribeittest
[ [SETTLE](): Promise<void, unknown>Waits for it if it is a promise; its rejection is the callback's error.
[ [KIND](): string"promise", "function" or "value".