Skip to content
velt/test exports

velt/test

API reference

The 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.

import { describe, it, expect } from "velt/test";

Exports

Re-exported from velt/test/expect

function expect<T>(actual: T): Expect<T>

The matchers for actual.

function

afterAll

#std/test/suite.vlt:207

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.

function

afterEach

#std/test/suite.vlt:226

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.

function

beforeAll

#std/test/suite.vlt:196

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.

function

beforeEach

#std/test/suite.vlt:215

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.

function

describe

#std/test/suite.vlt:157

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.

readonly actual: T

The value under test.

readonly negated: bool

After .not: every matcher checks the opposite.

constructor(actual: T, negated: bool)No doc comment yet
get 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.

interface

Settles

#std/test/suite.vlt:21

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.

[ [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".