Git Product home page Git Product logo

TSTyche

version license install-size coverage

The Essential Type Testing Tool.


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 { expect, test } from "tstyche";

function firstItem<T>(target: Array<T>): T | undefined {
  return target[0];
}

test("firstItem", () => {
  expect(firstItem(["a", "b", "c"])).type.toBe<string | undefined>();

  expect(firstItem()).type.toRaiseError("Expected 1 argument");
});

To organize, debug and plan tests TSTyche has:

  • test(), it() and describe() 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 functional tests:

import assert from "node:assert";
import test from "node:test";
import * as tstyche from "tstyche";

function secondItem<T>(target: Array<T>): T | undefined {
  return target[1];
}

test("handles numbers", () => {
  assert.strictEqual(secondItem([1, 2, 3]), 2);

  tstyche.expect(secondItem([1, 2, 3])).type.toBe<number | undefined>();
});

Here is the list of all matchers:

  • .toBe(), .toBeAssignableTo(), .toBeAssignableWith(), .toMatch() compare types or types of expression,
  • .toAcceptProps() checks types of JSX component's props,
  • .toHaveProperty() looks up keys on an object type,
  • .toRaiseError() captures the type error message or code,
  • .toBeString(), .toBeNumber(), .toBeVoid() and 9 more shorthand checks for primitive types.

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 TypeScript 4.8 and latest:

tstyche JsonObject --only external --target 4.8,latest

This simple! (And it has the watch mode too.)

Documentation

Visit https://tstyche.org to view the full documentation.

Feedback

If you have any questions or suggestions, start a discussion or open an issue on GitHub. Preferring a chat? Join our Discord server.

License

MIT © TSTyche

TSTyche's Projects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.