Template Test Files
When testing a type against many inputs, TSTyche can generate tests from a template file.
Usage
To mark a test file as a template, place the // @tstyche template comment directive at the top. When the directive is found, the default export is interpreted as type test text.
For example, the following:
// @tstyche template -- For documentation, see: https://tstyche.org/guides/template-test-files
let = `import { expect, test } from "tstyche";
`;
for (const of ["string", "number"]) {
+= `test("is ${} a string?", () => {
expect<${}>().type.toBe<string>();
});
`;
}
export default ;is interpreted as:
import { , } from "tstyche";
("is string a string?", () => {
<string>()..<string>();
});
("is number a string?", () => {
<number>()..<string>();
});The type test text is loaded via import() and replaced programmatically under the same file name. Therefore, the template must be a TypeScript file that Node.js can execute directly without transpilation. Fortunately, running TypeScript code with Node.js is now possible .
Last updated on