Test
tyrus:test is the test framework included with the language. Suites are written with describe, tests with test or its alias it, and checks with expect. tyrus test discovers the test files, compiles each one into its own binary, and reports every result.
tyrus
import { describe, it, expect } from "tyrus:test";
const discount = (total: i32): i32 => {
if (total >= 100) {
return total / 10;
}
return 0;
};
describe("discount", () => {
it("is zero below 100", () => {
expect(discount(99)).toBe(0);
});
describe("from 100 on", () => {
it("is ten percent", () => {
expect(discount(250)).toBe(25);
});
});
});Every name is imported explicitly, as with any other native module. A test file is any file whose name ends in .test.tyr; __tests__/ is the conventional folder for them, but not a required one.
API
- describe: group tests into a named suite; suites can nest.
- test / it: register a named test.
- expect: check a value with a matcher, inverted with
.not. - Hooks:
beforeAll,afterAll,beforeEachandafterEach. - Modifiers:
.skip,.onlyand.todoon tests and suites. - Running Tests: discovery, command-line options, and the report.
