Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inadarei/fakepromise
Fake Promise Based on Timeout
https://github.com/inadarei/fakepromise
promise testing
Last synced: 27 days ago
JSON representation
Fake Promise Based on Timeout
- Host: GitHub
- URL: https://github.com/inadarei/fakepromise
- Owner: inadarei
- License: mit
- Created: 2017-12-04T00:58:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-17T15:27:34.000Z (almost 3 years ago)
- Last Synced: 2024-11-23T00:46:41.131Z (about 1 month ago)
- Topics: promise, testing
- Language: JavaScript
- Size: 3.67 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![NPM Version][npm-img]][npm-url]
[![Code Climate Badge][codeclimate-img]][codeclimate-url]
[![Test Coverage][coverage-img]][coverage-url]## What Is it?
How many times have you been testing something that involves a promise, but you
wanted a fake promise, because the important thing is the async workflow, not
what the promise does? Have you hastily coded something-up with a setTimeout?
Are you annoyed with having to waste time on doing that repeatedly? Be annoyed
no more! Ultimate solution is here! And it has 100% test coverage, so it's very
reliable :)## TL;DR
If you need a fake promise that resolves in up to N milliseconds and returns a
predictable output – Fake Promise does exactly that.## Usage:
Async/Await:
```javascript
const fakepromise = require('fakepromise');
const myResult = await fakepromise.promise(2000, "this is returned");
```will give you a promise that takes *up to* 2000 milliseconds to execute and
resolves with "this is returned".Ye olde promises-way:
```javascript
const fakepromise = require('fakepromise');
const user = {"name" : "micky", role: "mouse"};
fakepromise.promise(2000, user).then( msg => {
console.log(msg);
});
```## Alternatives
If you are already using Bluebird, the
[Promise.delay()](http://bluebirdjs.com/docs/api/promise.delay.html) is almost
identical, except it delays by the exact number of milliseconds where we
introduce some fun randomness by delaying "up to" the number of milliseconds.## License
[MIT](LICENSE)
[npm-img]: https://img.shields.io/npm/v/fakepromise.svg?style=flat
[npm-url]: https://www.npmjs.com/package/fakepromise
[codeclimate-img]: https://codeclimate.com/github/inadarei/fakepromise/badges/gpa.svg
[codeclimate-url]: https://codeclimate.com/github/inadarei/fakepromise
[coverage-img]: https://api.codeclimate.com/v1/badges/cb7dfc4827bac808b77b/test_coverage
[coverage-url]: https://codeclimate.com/github/inadarei/fakepromise/test_coverage