diff --git a/README.md b/README.md index 2359213..b6ac8db 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ define('Car', ['SteeringWheel'], function(SteeringWheel){ Car.prototype.getSteeringWheelColor = function getSteeringWheelColor(){ return this.steeringWheel.color; - } + }; return Car; }); @@ -73,7 +73,7 @@ define([ afterEach(function(done){ bogus.reset(done); - }) + }); describe('Car', function(){ describe('getSteeringWheelColor method', function(){ @@ -88,6 +88,29 @@ define([ }); ``` +### Promises + +Both `bogus.require` and `bogus.reset` return promises. The `beforeEach` and +`afterEach` in the example above can be written as: + +```javascript +beforeEach(function(){ + var fakeSteeringWheel = function(){ + this.color = 'blue'; + }; + + bogus.stub('SteeringWheel', fakeSteeringWheel); + + return bogus.require('Car').then(function(module){ + Car = module; + }); +}); + +afterEach(function(){ + return bogus.reset(); +}); +``` + ### Stub multiple dependencies If you're stubbing several dependencies, you can pass a map of them to `stub` diff --git a/bogus.js b/bogus.js index fe71bdd..8ee2fc6 100644 --- a/bogus.js +++ b/bogus.js @@ -2,6 +2,20 @@ define(['require'], function(require){ 'use strict'; + // Modified (not to use global) and minified from https://github.com/timjansen/PinkySwear.js + /* jshint ignore:start */ + var pinkySwear = (function(){function n(n){return"function"==typeof n}function t(n){return"object"==typeof n}function e(n){"undefined"!=typeof setImmediate?setImmediate(n):"undefined"!=typeof process&&process.nextTick?process.nextTick(n):setTimeout(n,0)}function r(o){var c,i=[],f=[],a=function(n,t){return null==c&&null!=n&&(c=n,i=t,f.length&&e(function(){for(var n=0;n