Skip to Content
ReferenceTesting API

Testing API

TSTyche ships testing helpers to organize tests and run mode flags to focus or skip them.

Run Mode Flags

To focus or skip groups and tests, append the run mode flags to any describe() or test(). The flags are inherited from the parent.

import { , , } from "tstyche"; .("string", () => { ("is a string?", () => { <string>()..<string>(); }); .("does not run", () => { <string>()...<string>(); }); }); ("number", () => { ("does not run", () => { <number>()..<number>(); }); .("is not a number?", () => { <string>()...<number>(); }); }); .("to be implemented");

.only

Marks a group or a test as focused. When there are focused groups, tests or assertions in a file, only those will run.

.skip

Marks a group or a test as skipped. The test runner will ignore anything skipped and will suppress type errors inside the skipped callback functions.

.todo

Marks a group or a test as yet to be implemented. It does everything that the .skip flag does and also makes the callback function optional.

Use the // @tstyche fixme comment directive to mark any test() or describe() as failing. To learn more, see the Comment Directives page.

Testing Helpers

Using the helper functions is optional. For instance, instead of callbacks, you can use block statements  to scope variables, or code comments to name the tests:

import { } from "tstyche"; // is a string? { <string>()..<string>(); }

Both approaches work, but the helpers have more to offer. First, they provide the run mode flags. Second, you can filter tests by name from the command line through the --only and --skip options.

The name argument must always be a string literal, because the runner does not execute the code.

describe(name, callback)

  • name: string The name of the group.
  • callback: () => void | Promise<void> The function to create a scope for a group of tests.

Defines a group of tests. The describe() groups can be nested within each other.

import { , , } from "tstyche"; ("is a group?", () => { ("is a string?", () => { <string>()..<string>(); }); ("is a number?", () => { <number>()..<number>(); }); });

it(name, callback)

An alias for test(). For example, you can use it to write tests in the BDD style :

import { , , } from "tstyche"; ("number", () => { ("should be of type 'number'", () => { <number>()..<number>(); }); });

test(name, callback)

  • name: string The name of the test.
  • callback: () => void | Promise<void> The function with a code snippet and assertions.

Defines a single test.

import { , } from "tstyche"; ("is a string?", () => { <string>()..<string>(); });
Last updated on