fakepromise

1.0.6 • Public • Published

NPM Version Code Climate Badge Test Coverage

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:

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:

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() 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

Readme

Keywords

Package Sidebar

Install

npm i fakepromise

Weekly Downloads

8

Version

1.0.6

License

MIT

Unpacked Size

92.1 kB

Total Files

34

Last publish

Collaborators

  • irakli
  • randallsquared