An open API service indexing awesome lists of open source software.

https://github.com/crbroughton/ts-test-utils

A collection of testing helper types
https://github.com/crbroughton/ts-test-utils

bun testing type-testing types typescript utility

Last synced: 3 months ago
JSON representation

A collection of testing helper types

Awesome Lists containing this project

README

          

# ts-test-utils

A collection of helper TypeScript types to test other TypeScript types. This collection so far includes:

- Expect - The main helper; Use this with the below types
- Equals - Check for equality between two types
- Assignable - Check if one type is assignable to another type
- Excludes - Check if a type doesn't contain another type
- Includes - Check if a type includes another type
- Extends - Check if one type is extending another type
- IsArray - Checks if a type is an array
- IsNotArray - Checks if a type is not an array
- Length - Check a given types length; Combine this with the 'Equals' type checker
- Position - Returns a type in the given position of an array; Combine this with the 'Equals' type checker
- IsNullable - Check if a type is nullable
- IsNonNullable - Check if a type is not nullable
- IsUndefined - Check if a type is undefined
- IsNonUndefined - Check if a type is not undefined
- IsNullish - Check if a type is either undefined or null
- IsNonNullish - Check if a type is neither undefined or null
- IsVoid - Check if a type is void
- IsNonVoid - Check if a type is not void
- NonVoid - Remove void from a union that contains void
- isUnionEqual - Check for equality between two unions

## Installation

To install `ts-test-utils` with Bun, run the following command:

```bash
bun i -D @crbroughton/ts-test-utils
```

## Getting Started

You can use these types to test other types:

```typescript
// This should return true
type Result = Expect>
```

For testing types that are expected to not equal each-other, you can
add the `//@ts-expect-error` comment to tell the TypeScript compiler
that a `false` return is expected, and that a match is not expected:

```typescript
// @ts-expect-error - Object / Record failing the equality checker
type ResultRecord = Expect>
```

You can combine these types with existing types. As an example,
here is the 'Equals' type being used to check a functions return type:

```typescript
function myFunction() {
return {
id: 1,
name: 'Craig',
}
}
type Result = Expect, { id: number, name: string }>>
```

## Development Installation

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run index.ts
```

This project was created using `bun init` in bun v1.1.3. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.