sneer
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i sneer

Weekly Downloads

6

Version

1.0.1

License

MIT

Unpacked Size

4.71 kB

Total Files

5

Last publish

Collaborators

  • vdsabev