npm.io
1.0.1 • Published 7 years ago

sneer

Licence
MIT
Version
1.0.1
Deps
0
Size
5 kB
Vulns
0
Weekly
0
Stars
3

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 }
  }
});

Keywords