Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/djaler/simple-promise-mock
A tiny utility function to create a controlled promise instance with additional methods to resolve or reject it
https://github.com/djaler/simple-promise-mock
mock promise test
Last synced: 6 days ago
JSON representation
A tiny utility function to create a controlled promise instance with additional methods to resolve or reject it
- Host: GitHub
- URL: https://github.com/djaler/simple-promise-mock
- Owner: Djaler
- License: mit
- Created: 2022-04-10T14:58:38.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-05-23T22:32:53.000Z (over 2 years ago)
- Last Synced: 2024-12-09T22:39:07.937Z (about 1 month ago)
- Topics: mock, promise, test
- Language: TypeScript
- Homepage:
- Size: 59.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![npm](https://img.shields.io/npm/v/simple-promise-mock?style=for-the-badge)](https://www.npmjs.com/package/simple-promise-mock)
# Simple Promise Mock
> A tiny utility function to create a controlled promise instance with additional methods to resolve or reject it.
## Why?
Because often in tests you need to mock async function and manually control when it resolves or rejects.
## Install
```sh
npm install --save simple-promise-mock
```## Usage
```js
import { createPromiseMock } from 'simple-promise-mock';const promise = createPromiseMock();
promise.then(() => {
// do something
}).catch(() => {
// do something
});promise.resolve('foo');
// or
promise.reject('bar');
```