sneer

Type-safe mocking utilities for reliable unit tests

MIT License

Downloads
142
Stars
3
Committers
1

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 }
  }
});
Package Rankings
Top 10.64% on Npmjs.org
Badges
Extracted from project README's
downloads version MIT License
Related Projects