Skip to content

Modifiers ​

Signaturetest.skip(name: string, callback: () => void): void
Signaturetest.only(name: string, callback: () => void): void
Signaturetest.todo(name: string): void
Signaturedescribe.skip(name: string, callback: () => void): void
Signaturedescribe.only(name: string, callback: () => void): void

test.skip lists a test as skipped without running it; its callback still has to compile. describe.skip skips every test in the suite, and the suite hooks do not run.

test.todo(name) lists a test that has not been written yet. Skipped tests and todos are counted separately in the summary.

it accepts the same modifiers, and so does an aliased import such as import { test as check } from "tyrus:test". test.concurrent and test.fails are not implemented yet and are reported as compile errors.

tyrus
import { describe, it, test, expect } from "tyrus:test";

describe("parser", () => {
    it("runs", () => {
        expect(1).toBe(1);
    });

    test.skip("waits for the new grammar", () => {
        expect(1).toBe(2);
    });

    test.todo("reports unicode columns");
});

describe.skip("legacy format", () => {
    it("is not run", () => {
        expect(1).toBe(2);
    });
});

Focus with .only ​

When any test or suite in a program is focused with .only, only focused tests run and the others count as skipped. .skip wins over .only: focusing never runs a test that was skipped on purpose.

tyrus
import { it, expect } from "tyrus:test";

it("is left out while another test is focused", () => {
    expect(1).toBe(1);
});

it.only("is the only test that runs", () => {
    expect(2).toBe(2);
});

One Test per Case ​

test.each(name, cases, callback) registers one test per case, named name [0], name [1], and so on. The callback takes one case; written inline, its parameter type is inferred from the cases. The cases must be an array literal, because they are unrolled when the program is compiled.

tyrus
import { describe, test, expect } from "tyrus:test";

const clamp = (value: i32, low: i32, high: i32): i32 => {
    if (value < low) {
        return low;
    }
    if (value > high) {
        return high;
    }
    return value;
};

describe("clamp", () => {
    test.each("keeps a value in range", [0, 5, 10], (value: i32) => {
        expect(clamp(value, 0, 10)).toBe(value);
    });
});