Ellisande / mockolate

Simple mocking framework for JS
MIT License
1 stars 3 forks source link

Add Support for Promises #6

Closed Ellisande closed 8 years ago

Ellisande commented 8 years ago

What kind of issue is this? (bug, feature, etc)

Feature

What is the proposed change?

Add an easy mechanism for mockFunction to return promises.

Why will this be beneficial?

It'll make life easier for people mocking functions that return promises.

Misc. info

Proposed example:

mockFunc.when(1).thenPromise.toReturn(2);
const myPromise = mockFunc(1);
myPromise.then(result => console.log(result));
//Result would be 2

mockFunc.when(2).thenPromise.toThrow(new Error('Die'))
const myPromise = mockFunc(1);
myPromise.catch(err => console.log(err.message));
//Would log 'Die'