Skip to content

KensioSoftware/smartass

Repository files navigation

@kensio/smartass

TypeScript-first test assertion functions with precise type narrowing via assertion signatures.

See TypeScript assertion functions / assertion signatures

The fluent expect().toBe() interface in Jest and Vitest is readable, but is unable to provide type information to TypeScript and IntelliSense.

This library provides assertion functions with assertion signatures so that you can benefit from the extra type information.

import { assertNonNullable } from '@kensio/smartass';

const user: { name: string } | undefined = getUser();
assertNonNullable(user);
// TypeScript now knows user is neither null nor undefined,
// so no need for ? or ! operators.
const userName = user.name;
import { assertOneOf } from '@kensio/smartass';

const status = getStatus();
assertOneOf(status, ['pending', 'active', 'completed']);
// TypeScript now knows status is of type 'pending' | 'active' | 'completed'

Installation

npm install @kensio/smartass

Assertion functions

About

TypeScript-first test assertion functions with precise type narrowing via assertion signatures.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors