Socket
Socket
Sign inDemoInstall

tstyche

Package Overview
Dependencies
1
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tstyche

The Essential Type Testing Tool.


Version published
Weekly downloads
3.1K
decreased by-14.75%
Maintainers
1
Install size
182 kB
Created
Weekly downloads
 

Changelog

Source

[1.1.0] - 2024-02-27

Added

  • New! Support for Node.js 14 (#136)

  • Add the CancellationToken class (#135)

Fixed

  • Improve behavior of timeout errors (#133, #134)

Readme

Source

TSTyche

version license requirements install-size coverage discord

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.toEqual<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/strict";
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.toEqual<number | undefined>();
});

Here is the list of all matchers:

  • .toBeAssignable(), .toEqual(), .toMatch() compares types or types of expression,
  • .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!

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

Keywords

FAQs

Last updated on 27 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc