Everything You Need for Type Testing.
TSTyche is a type testing tool for TypeScript. It ships with describe()
and test()
helpers, expect
style assertions and a mighty test runner.
Helpers
If you are used to test JavaScript, a simple type test file should look familiar:
import { , } from "tstyche";
function < extends { : number }>(: , : ) {
return . === .;
}
("isSameLength", () => {
(([1, 2], [1, 2, 3]))..<boolean>();
(("one", "two"))..<boolean>();
()...(1, 2);
});
To organize, debug and plan tests TSTyche has:
test()
,it()
anddescribe()
helpers,- with
.only
,.skip
and.todo
run mode flags.
Assertions
The assertions can be used to write type tests (like in the above example) or mixed in your unit tests:
import from "node:assert";
import from "node:test";
import * as from "tstyche";
function (: number) {
if (typeof === "number" && !.()) {
return * 1000;
}
throw new ("Not a number");
}
("milliseconds", () => {
const = (10);
.(, 10_000);
.()..<number>();
// Will pass as a type test and not throw at runtime
.()...("20");
});
Here is the list of all matchers:
.toBe()
,.toBeAssignableTo()
,.toBeAssignableWith()
compare types or types of expression,.toAcceptProps()
checks the type of JSX component props,.toBeApplicable
ensures that the decorator function can be applied,.toBeCallableWith()
checks whether a function is callable with the given arguments,.toBeConstructableWith()
checks whether a class is constructable with the given arguments,.toHaveProperty()
looks up keys on an object type.
Runner
The tstyche
command is the heart of TSTyche. For example, it can select test files by path, filter tests by name and pass them through a range of TypeScript versions:
tstyche query-params --only multiple --target '>=5.0 <5.3'
This simple! (And it has watch mode too.)
Last updated on