Skip to content
/ sneer Public

Type-safe mocking utilities for reliable unit tests

License

Notifications You must be signed in to change notification settings

vdsabev/sneer

Repository files navigation

downloads version MIT License

Sneer 😏

Type-safe mocking utilities

Why?

You want to write test mocks in TypeScript while preserving type safety and getting meaningful type errors.

Installation

npm install sneer -D

Usage

import {
  mockPartial,
  mockPartialArray,
  mockRecursivePartial,
  mockRecursivePartialArray,
} from 'sneer';

mockPartial

mockPartialArray

Casts an object (or array of objects) to a type T while only requiring a partial implementation of the type to be passed. This allows us to easily mock an object while writing tests without having to define all of the properties of an object.

Example:

const store = mockPartial<Store<State>>({
  select: jest.fn((selector: (state: State) => any) => Observable.of(selector(state))),
});

mockRecursivePartial

mockRecursivePartialArray

Same as mockPartial and mockPartialArray, but recursively partial 🙃

Example:

const svg = mockRecursivePartial<SVGSVGElement>({
  x: {
    baseVal: { value: 1 }
  }
});

About

Type-safe mocking utilities for reliable unit tests

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published