a utility for testing promise code
A testing library for then-able promises.
- Implementation independent. Should work with any Promise/A+ conformant library. (Test suite runs against Q and When).
- Runs in Node or directly in the browser.
- Support for NPM and Component package managers.
- Test/Assertion framework agnostic. Support for Mocha and Chai built in.
See the example;
Node.js or Component
var PromiseTesting = require'promise-testing';var engine = ;
In the browser (included via script tag)
var engine = ;
If you are using any chai extensions (i.e. SinonChai) before calling the scanChai method.
Promises need to be wrapped by a wrapper object for testing.
var rawPromise = someServicecreatePromise;var wrappedPromise = enginewraprawPromise;
Functions that always return promises can be
patched for convenience
enginepatchsomeService'createPromise';//all calls to the patched function now return a wrappedPromisevar wrappedPromise1 = someServicecreatePromise;var wrappedPromise2 = someServicecreatePromise;
You can now use chai expectations just like you normally would, however they won't be run until the promise completes.
is equivalent to
promisethenexpectresulttoequal'hello';thendone; //No Error - test passesdone //There was an error - pass it to done;