Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vdsabev/sneer
Type-safe mocking utilities for reliable unit tests
https://github.com/vdsabev/sneer
mocking testing typescript unit-testing
Last synced: about 1 month ago
JSON representation
Type-safe mocking utilities for reliable unit tests
- Host: GitHub
- URL: https://github.com/vdsabev/sneer
- Owner: vdsabev
- License: mit
- Created: 2018-03-20T14:26:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-14T14:29:33.000Z (over 5 years ago)
- Last Synced: 2024-09-30T16:46:27.621Z (about 2 months ago)
- Topics: mocking, testing, typescript, unit-testing
- Language: TypeScript
- Homepage:
- Size: 7.81 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![downloads][downloads-badge]][npmcharts]
[![version][version-badge]][package]
[![MIT License][license-badge]][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
```ts
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:
```ts
const store = mockPartial>({
select: jest.fn((selector: (state: State) => any) => Observable.of(selector(state))),
});
```### `mockRecursivePartial`
### `mockRecursivePartialArray`
Same as `mockPartial` and `mockPartialArray`, but recursively partial 🙃Example:
```ts
const svg = mockRecursivePartial({
x: {
baseVal: { value: 1 }
}
});
```[version-badge]: https://img.shields.io/npm/v/sneer.svg?style=flat-square
[package]: https://www.npmjs.com/package/sneer
[downloads-badge]: https://img.shields.io/npm/dm/sneer.svg?style=flat-square
[npmcharts]: https://npmcharts.com/compare/sneer
[license-badge]: https://img.shields.io/npm/l/sneer.svg?style=flat-square
[license]: https://github.com/vdsabev/sneer/blob/master/LICENSE.md