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