Modifiers
test.skip(name: string, callback: () => void): voidtest.only(name: string, callback: () => void): voidtest.todo(name: string): voiddescribe.skip(name: string, callback: () => void): voiddescribe.only(name: string, callback: () => void): voidtest.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.
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.
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.
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);
});
});