0.0.12 • Published 11 years ago

promise-testing v0.0.12

Weekly downloads
3
License
MIT
Repository
github
Last release
11 years ago

Promise Testing Build StatusDependency StatusdevDependency Status

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.

Quick Start

See the example;

Usage

Create a new test engine.

Node.js or Component

var PromiseTesting = require('promise-testing');
var engine = new PromiseTesting();

In the browser (included via script tag)

var engine = new PromiseEngine();

Add Chai Support.

If you are using any chai extensions (i.e. SinonChai) before calling the scanChai method.

engine.scanChai(chai);

Wrap Promises or Patch Methods.

Promises need to be wrapped by a wrapper object for testing.

var rawPromise = someService.createPromise();
var wrappedPromise = engine.wrap(rawPromise);

Functions that always return promises can be patched for convenience

engine.patch(someService,'createPromise');
//all calls to the patched function now return a wrappedPromise
var wrappedPromise1 = someService.createPromise();
var wrappedPromise2 = someService.createPromise();

Expectations

You can now use chai expectations just like you normally would, however they won't be run until the promise completes.

wrappedPromise.then.expect.result.to.equal('hello').then.notify(done);

is equivalent to

promise.then(function(result){
	expect(result).to.equal('hello');
}).then(
	function(){
		done(); //No Error - test passes
	},
	done //There was an error - pass it to done
);
0.0.12

11 years ago

0.0.11

11 years ago

0.0.10

11 years ago

0.0.9

11 years ago

0.0.8

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago

0.0.0

11 years ago