Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/parzh/tyte
jest testing typescript
Last synced: 2 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/parzh/tyte
- Owner: parzh
- License: mit
- Created: 2021-01-16T21:47:26.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-06-14T10:42:53.000Z (over 3 years ago)
- Last Synced: 2023-03-03T21:55:33.440Z (almost 2 years ago)
- Topics: jest, testing, typescript
- Language: TypeScript
- Size: 88.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `tyte`
Write Jest tests for TypeScript types.
# Usage
> Also see **Caveats** section below
```ts
export type MyNumber = number;
export type MyFunction = (input: string) => boolean;
```## Positive testing:
```ts
test("MyNumber should resolve to a number", tyte((value: MyNumber) => {
tyte.expectType(value);
}));describe("MyFunction", () => {
it("should take a string input", tyte((subject: MyFunction) => {
tyte.fn.expectParams<[string]>(subject);
}));it("should return a boolean", tyte((subject: MyFunction) => {
tyte.fn.expectReturns(subject);
}));
});
```## Negative testing:
```ts
test("MyNumber should not resolve to a string", tyte((value: MyNumber) => {
// @ts-expect-error
tyte.expectType(value);
}));
```## Use several subjects in test callback:
```ts
test("MyNumber should resolve to a number", tyte((
value: MyNumber,
values: MyNumber[],
) => {
tyte.expectType(value);
tyte.expectType(values);
}));
```## Iterate over several subjects in [`.each` methods]:
```ts
type Forward = "forward";
type Vertical = "up" | "down" | Forward;
type Horizontal = "left" | "right" | Forward;test.each([
[ "Vertical", tyte.subject as Vertical & Forward ],
[ "Horizontal", tyte.subject as Horizontal & Forward ],
])("%s should include 'forward'", (identifier, subject) => {
tyte.expectType<"forward">(subject);
});
```## Caveats
- Currently, it is not possible to use `tyte()` as a function in [`.each` methods], as in:
```ts
test.each(list)("should ...", tyte((element) => {
// ...
}));
```Such code will produce compilation errors.
> Any suggestions and PRs are very welcome!
[`.each` methods]: https://jestjs.io/docs/en/api#methods