Skip to content

inadarei/fakepromise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Fake Promise Based on Timeout

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published