https://github.com/tstyche/tstyche
The Essential Type Testing Tool.
https://github.com/tstyche/tstyche
developer-tools expect test test-runner testing-tools types typescript
Last synced: about 1 month ago
JSON representation
The Essential Type Testing Tool.
- Host: GitHub
- URL: https://github.com/tstyche/tstyche
- Owner: tstyche
- License: mit
- Created: 2023-11-09T12:57:33.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T20:36:00.000Z (over 1 year ago)
- Last Synced: 2024-10-29T22:49:49.882Z (over 1 year ago)
- Topics: developer-tools, expect, test, test-runner, testing-tools, types, typescript
- Language: JavaScript
- Homepage: https://tstyche.org
- Size: 5.34 MB
- Stars: 65
- Watchers: 4
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# TSTyche
[![version][version-badge]][version-url]
[![license][license-badge]][license-url]
[![install-size][install-size-badge]][install-size-url]
[![coverage][coverage-badge]][coverage-url]
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:
```ts
import { expect, test } from "tstyche";
function isSameLength(a: T, b: T) {
return a.length === b.length;
}
test("isSameLength", () => {
expect(isSameLength([1, 2], [1, 2, 3])).type.toBe();
expect(isSameLength("one", "two")).type.toBe();
expect(isSameLength).type.not.toBeCallableWith(1, 2);
});
```
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 unit tests:
```ts
import assert from "node:assert";
import test from "node:test";
import * as tstyche from "tstyche";
function toMilliseconds(value: number) {
if (typeof value === "number" && !Number.isNaN(value)) {
return value * 1000;
}
throw new Error("Not a number");
}
test("toMilliseconds", () => {
const sample = toMilliseconds(10);
assert.equal(sample, 10_000);
tstyche.expect(sample).type.toBe();
// Will pass as a type test and not throw at runtime
tstyche.expect(toMilliseconds).type.not.toBeCallableWith("20");
});
```
Here is the list of all matchers:
- `.toBe()`, `.toBeAssignableFrom()`, `.toBeAssignableTo()` 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 to run the tests against specific versions of TypeScript:
```shell
tstyche query-params --only multiple --target '>=5.6'
```
This simple! (And it has watch mode too.)
## Documentation
Visit [tstyche.org](https://tstyche.org) to view the full documentation.
## License
[MIT][license-url] © TSTyche
[version-badge]: https://badgen.net/npm/v/tstyche
[version-url]: https://npmjs.com/package/tstyche
[license-badge]: https://badgen.net/github/license/tstyche/tstyche
[license-url]: https://github.com/tstyche/tstyche/blob/main/LICENSE.md
[install-size-badge]: https://badgen.net/packagephobia/install/tstyche
[install-size-url]: https://packagephobia.com/result?p=tstyche
[coverage-badge]: https://badgen.net/codacy/coverage/a581ca5c323a455886b7bdd9623c4ec8
[coverage-url]: https://app.codacy.com/gh/tstyche/tstyche/coverage/dashboard