+11
| { | ||
| "preset": "node-style-guide", | ||
| // allow some slop to account for legacy code | ||
| "validateQuoteMarks": { "mark": "'", "escape": true }, | ||
| "requireCapitalizedComments": { "allExcept": ["jshint"] }, | ||
| "excludeFiles": [ | ||
| "node_modules/**", | ||
| "clean/**" | ||
| ] | ||
| } |
+2
| /* Not recommended! Mutate the global Promise. */ | ||
| require('./lib')(global.Promise, 'HULK SMASH'); |
+1
-1
| { | ||
| "predef": [ "Promise", "describe", "specify", "it" ], | ||
| "predef": [ "describe", "specify", "it" ], | ||
| "node": true | ||
| } |
+2
-0
| language: node_js | ||
| node_js: | ||
| - "iojs" | ||
| - "0.12" | ||
| - "0.11" | ||
| - "0.10" | ||
| - "0.8" |
+8
-0
@@ -0,1 +1,9 @@ | ||
| # prfun 2.0.0 (2015-04-23) | ||
| * Breaking change: `prfun` now creates a subclass of `Promise` by | ||
| default, instead of smashing the global `Promise`. This only works | ||
| if your `Promise` implementation properly supports the ES6 subclass | ||
| semantics -- `es6-shim` is known to implement the ES6 spec properly. | ||
| To smash the global `Promise` like in the bad old days, use | ||
| `require('prfun/smash')`. | ||
| # prfun 1.0.2 (2014-11-06) | ||
@@ -2,0 +10,0 @@ |
+2
-2
@@ -1,3 +0,3 @@ | ||
| // chain over to `prfun/wrap`, which allows users to specify a non-default | ||
| // Chain over to `prfun/wrap`, which allows users to specify a non-default | ||
| // Promise implementation if they prefer. | ||
| require('./wrap')(); | ||
| module.exports = require('./wrap')(); |
+57
-25
| // Utility functions for ES6 Promises. | ||
| module.exports = function(Promise) { | ||
| "use strict"; | ||
| module.exports = function(ParentPromise, smash) { | ||
| 'use strict'; | ||
| if (!Promise) { Promise = global.Promise; } | ||
| // Use Promise implementation from es6-shim if there isn't already one | ||
| if (!ParentPromise) { ParentPromise = global.Promise; } | ||
| // Try to use Promise implementation from es6-shim if there isn't already one | ||
| // installed. | ||
| if (!Promise) { require('es6-shim'); Promise = global.Promise; } | ||
| if (!ParentPromise) { | ||
| try { | ||
| require('es6-shim'); | ||
| } catch (e) { | ||
| throw new Error('No Promise implementation found. ' + | ||
| "Install the optional dependencies to use es6-shim's Promises."); | ||
| } | ||
| ParentPromise = global.Promise; | ||
| } | ||
| // Create a new Promise subclass (this is less cumbersome in es6!) | ||
| var PrFunPromise = function PrFunPromise(exec) { | ||
| return ParentPromise.call(this, exec); | ||
| }; | ||
| Object.setPrototypeOf(PrFunPromise, ParentPromise); | ||
| PrFunPromise.prototype = Object.create(ParentPromise.prototype); | ||
| PrFunPromise.prototype.constructor = PrFunPromise; | ||
| // Sometimes we just need to smash things (sigh) | ||
| var Promise = smash ? ParentPromise : PrFunPromise; | ||
| // Sanity-check (warn users if this is all going to go pear-shaped) | ||
| try { | ||
| if (!(Promise.resolve(42) instanceof Promise)) { | ||
| throw('Bad implementation'); | ||
| } | ||
| } catch (ex) { | ||
| throw new Error('Bad Promise implementation: does not support ' + | ||
| 'ES6 subclassing. Use prfun/smash.'); | ||
| } | ||
| // ---------- collections -------------- | ||
@@ -188,4 +217,4 @@ | ||
| // compatibility with q/when/jquery/etc. | ||
| // use of this interface is discouraged. | ||
| // Compatibility with q/when/jquery/etc. | ||
| // Use of this interface is discouraged. | ||
| var Deferred = function Deferred() { }; | ||
@@ -197,3 +226,3 @@ Object.defineProperties(Deferred.prototype, { | ||
| return { resolve: this.resolve, reject: this.reject }; | ||
| } | ||
| }, | ||
| }, | ||
@@ -203,3 +232,4 @@ callback: { | ||
| get: function() { | ||
| var resolve = this.resolve, reject = this.reject; | ||
| var resolve = this.resolve; | ||
| var reject = this.reject; | ||
| return function(err, value) { | ||
@@ -209,4 +239,4 @@ if (err) { return reject(err); } | ||
| }; | ||
| } | ||
| } | ||
| }, | ||
| }, | ||
| }); | ||
@@ -276,3 +306,3 @@ Promise.defer = function() { | ||
| var P = this || Promise; | ||
| if (arguments.length===1) { | ||
| if (arguments.length === 1) { | ||
| ms = pValue; | ||
@@ -298,3 +328,3 @@ pValue = undefined; | ||
| var makeRejector = function(reject, message, ms) { | ||
| // create this function in an outer scope so that we don't inadvertently | ||
| // Create this function in an outer scope so that we don't inadvertently | ||
| // keep a reference to the promise here. Perhaps this is overkill. | ||
@@ -319,3 +349,5 @@ var id = setTimeout(function() { reject(new TimeoutError(message)); }, ms); | ||
| return P.all(arguments).then(function(args) { | ||
| var fn = args[0], ctx = args[1], rest = args.slice(2); | ||
| var fn = args[0]; | ||
| var ctx = args[1]; | ||
| var rest = args.slice(2); | ||
| return new P(function(resolve, reject) { | ||
@@ -333,3 +365,3 @@ try { | ||
| var promise = this; | ||
| if (arguments.length<=1) { return promise['catch'](predicate); } | ||
| if (arguments.length <= 1) { return promise['catch'](predicate); } | ||
| var predicates = Array.prototype.slice.call(arguments); | ||
@@ -347,3 +379,3 @@ handler = predicates.pop(); | ||
| return function(e) { | ||
| throw new TypeError('caught filter must inherit from Error '+ | ||
| throw new TypeError('caught filter must inherit from Error ' + | ||
| 'or be a simple predicate function'); | ||
@@ -354,3 +386,3 @@ }; | ||
| return promise['catch'](function(e) { | ||
| for (var i=0; i<predicates.length; i++) { | ||
| for (var i = 0; i < predicates.length; i++) { | ||
| if (predicates[i](e)) { | ||
@@ -360,3 +392,3 @@ return handler.call(this, e); | ||
| } | ||
| // re-throw | ||
| // Re-throw | ||
| throw e; | ||
@@ -455,3 +487,3 @@ }); | ||
| nodeFunction.apply(self, args); | ||
| } catch(e) { | ||
| } catch (e) { | ||
| reject(e); | ||
@@ -504,3 +536,3 @@ } | ||
| */ | ||
| Promise.guard.n = function (allowed) { | ||
| Promise.guard.n = function(allowed) { | ||
| var count, waiting; | ||
@@ -515,3 +547,3 @@ | ||
| } | ||
| if(waiting.length) { | ||
| if (waiting.length) { | ||
| waiting.shift()(exit); | ||
@@ -523,3 +555,3 @@ } | ||
| return new Promise(function(resolve) { | ||
| if(count < allowed) { | ||
| if (count < allowed) { | ||
| resolve(exit); | ||
@@ -543,3 +575,3 @@ } else { | ||
| // create a new Promise subclass (this is less cumbersome in es6, sigh) | ||
| var BoundPromise = function(exec) { | ||
| var BoundPromise = function BoundPromise(exec) { | ||
| return SuperPromise.call(this, exec); | ||
@@ -586,4 +618,4 @@ }; | ||
| generator = makeGenerator.apply(this, arguments); | ||
| callback = continuer.bind(continuer, "next"); | ||
| errback = continuer.bind(continuer, "throw"); | ||
| callback = continuer.bind(continuer, 'next'); | ||
| errback = continuer.bind(continuer, 'throw'); | ||
| return callback(); | ||
@@ -590,0 +622,0 @@ }; |
+7
-4
@@ -16,2 +16,5 @@ // Extra support for mocha. | ||
| var assert = require('assert'); | ||
| // always use es6-shim promises for tests, since platform Promises may | ||
| // not properly implement ES6 subclasses | ||
| require('es6-shim'); | ||
@@ -27,3 +30,3 @@ // wrap specify/it and ensure that they always return a promise if synchronous. | ||
| assert.ok(!result, | ||
| "Tests with callbacks should not return a value: "+title); | ||
| 'Tests with callbacks should not return a value: ' + title); | ||
| }; | ||
@@ -35,3 +38,3 @@ } else if (cb.length === 0) { | ||
| assert.ok(result && typeof result.then === 'function', | ||
| "Synchronous tests should return a promise: "+title); | ||
| 'Synchronous tests should return a promise: ' + title); | ||
| return result; | ||
@@ -52,3 +55,3 @@ }; | ||
| get: function() { return realSpecify; }, | ||
| set: function(v) { realSpecify = onlypromises(v); } | ||
| set: function(v) { realSpecify = onlypromises(v); }, | ||
| }); | ||
@@ -59,3 +62,3 @@ | ||
| get: function() { return realIt; }, | ||
| set: function(v) { realIt = onlypromises(v); } | ||
| set: function(v) { realIt = onlypromises(v); }, | ||
| }); |
+7
-6
| { | ||
| "name": "prfun", | ||
| "version": "1.0.2", | ||
| "version": "2.0.0", | ||
| "description": "Helper functions for ES6 promises", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "jshint . && mocha --harmony-generators" | ||
| "test": "jshint . && jscs . && mocha --harmony-generators" | ||
| }, | ||
@@ -26,9 +26,10 @@ "repository": { | ||
| "devDependencies": { | ||
| "mocha": "~1.18.2", | ||
| "jshint": "~2.4.3", | ||
| "glob": "~3.2.3" | ||
| "es6-shim": ">=0.10.0 <1.0.0-0", | ||
| "jscs": "~1.12.0", | ||
| "jshint": "~2.7.0", | ||
| "mocha": "~2.2.4" | ||
| }, | ||
| "dependencies": { | ||
| "optionalDependencies": { | ||
| "es6-shim": ">=0.10.0 <1.0.0-0" | ||
| } | ||
| } |
+46
-9
@@ -12,3 +12,3 @@ # prfun | ||
| This package supplies them. It also loads [es6-shim] for the basic | ||
| This package supplies them. It optionally loads [es6-shim] for the basic | ||
| `Promise` implementation, if there is not already a `Promise` implemention | ||
@@ -22,15 +22,52 @@ present. | ||
| To use the promise implementation from your ES6 engine (or [es6-shim], if | ||
| you are running on an ES5 engine): | ||
| By default `prfun` creates a `Promise` subclass, using ES6 semantics. | ||
| This means you use it like: | ||
| ``` | ||
| require('prfun'); | ||
| var Promise = require('prfun'); // subclasses global.Promise | ||
| // note that global.Promise !== Promise here | ||
| ``` | ||
| or | ||
| ``` | ||
| var SomeOtherPromise = require( /*something*/ ); | ||
| var Promise = require('prfun/wrap')( SomeOtherPromise ); | ||
| ``` | ||
| Note that the `SomeOtherPromise` implementation must support `Promise` | ||
| subclassing using ES6 semantics. ([es6-shim]'s implementation is | ||
| known to do so.) We will call the subclass created by `prfun` a | ||
| "`prfun` `Promise`". | ||
| // Use Promise.reduce, etc... | ||
| According to the ES6 `Promise` spec, all `Promise` methods (including | ||
| the new ones added by `prfun`) will return an instance of the subclass | ||
| when invoked on an instance of the subclass. That is, if you are given | ||
| a `prfun` `Promise` and you call `then` on it, the result will be | ||
| another `prfun` `Promise`. So within your own code you can assume | ||
| that all `prfun` helper methods will be present, and they will all | ||
| return `prfun` `Promise`s which also contain all the `prfun` helper | ||
| methods. | ||
| If your code is given a promise from an outside API, and you can't | ||
| guarantee that it is a `prfun` Promise, then you can use | ||
| `Promise.resolve` in order to cast the outside promise to a `prfun` | ||
| `Promise`. For example: | ||
| ``` | ||
| var Promise = require('prfun'); // this is a "prfun Promise" | ||
| To use a different promise implementation: | ||
| function myApi(externalPromise) { | ||
| return Promise.resolve(externalPromise).tap(function(value) { | ||
| // we can call 'tap' after resolving the external promise | ||
| }); // this result will also be a "prfun Promise" | ||
| } | ||
| ``` | ||
| var prfun = require('prfun/wrap'); | ||
| var Promise = prfun( require('bluebird'/*etc*/) ); | ||
| In order to *modify the global `Promise` object* (instead of | ||
| subclassing), use: | ||
| ``` | ||
| require('prfun/smash'); | ||
| // global.Promise.reduce, global.Promise.tap, etc, now exist. | ||
| ``` | ||
| This is how `prfun` worked by default prior to version 2.0, but it | ||
| it not recommended: stomping on global objects is never a good idea, | ||
| and future changes to the `Promise` object in ES7 or incompatible | ||
| methods added by your third-party `Promise` implementation or other | ||
| libraries could break your code in mysterious ways. | ||
@@ -1399,3 +1436,3 @@ ## API | ||
| Copyright (c) 2014 C. Scott Ananian | ||
| Copyright (c) 2014-2015 C. Scott Ananian | ||
@@ -1402,0 +1439,0 @@ Portions are Copyright (c) 2014 Petka Antonov |
+262
-264
@@ -1,8 +0,6 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| // platform Promises don't properly implement ES6 subclasses, so | ||
| // always use es6-shim here. | ||
| require('es6-shim'); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -13,3 +11,3 @@ var fulfilled = Promise.resolve.bind(Promise); | ||
| var THIS = {name: "this"}; | ||
| var THIS = {name: 'this'}; | ||
@@ -22,7 +20,7 @@ function CustomError1() {} | ||
| describe("when using .bind", function() { | ||
| describe("with finally", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "in straight-forward handler", function() { | ||
| return fulfilled().bind(THIS)['finally'](function(){ | ||
| describe('when using .bind', function() { | ||
| describe('with finally', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('in straight-forward handler', function() { | ||
| return fulfilled().bind(THIS)['finally'](function() { | ||
| assert(this === THIS); | ||
@@ -32,3 +30,3 @@ }); | ||
| specify( "after promise returned from finally resolves", function() { | ||
| specify('after promise returned from finally resolves', function() { | ||
| var d = pending(); | ||
@@ -38,3 +36,3 @@ var promise = d.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| waited = true; | ||
@@ -44,5 +42,5 @@ d.resolve(); | ||
| return fulfilled().bind(THIS)['finally'](function(){ | ||
| return fulfilled().bind(THIS)['finally'](function() { | ||
| return promise; | ||
| })['finally'](function(){ | ||
| })['finally'](function() { | ||
| assert(waited); | ||
@@ -56,5 +54,5 @@ assert(this === THIS); | ||
| describe("with .delay", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "in straight-forward handler", function() { | ||
| describe('with .delay', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('in straight-forward handler', function() { | ||
| return fulfilled(3).bind(THIS).delay(5).then(function(v) { | ||
@@ -65,3 +63,3 @@ assert(v === 3); | ||
| }); | ||
| specify( "in rejected handler", function() { | ||
| specify('in rejected handler', function() { | ||
| return rejected(3).bind(THIS).delay(5).then(assert.fail, function(v) { | ||
@@ -76,5 +74,5 @@ assert(v === 3); | ||
| describe("with .timeout", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "in straight-forward handler", function() { | ||
| describe('with .timeout', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('in straight-forward handler', function() { | ||
| return fulfilled(3).bind(THIS).timeout(500).then(function(v) { | ||
@@ -85,4 +83,4 @@ assert(v === 3); | ||
| }); | ||
| specify( "in rejected handler", function() { | ||
| return rejected(3).bind(THIS).timeout(500).then(assert.fail, function(v){ | ||
| specify('in rejected handler', function() { | ||
| return rejected(3).bind(THIS).timeout(500).then(assert.fail, function(v) { | ||
| assert(v === 3); | ||
@@ -93,6 +91,6 @@ assert(this === THIS); | ||
| specify( "in rejected handler after timeout", function() { | ||
| return new Promise(function(){}) | ||
| specify('in rejected handler after timeout', function() { | ||
| return new Promise(function() {}) | ||
| .bind(THIS).timeout(10).then(assert.fail) | ||
| .caught(Promise.TimeoutError, function(err){ | ||
| .caught(Promise.TimeoutError, function(err) { | ||
| assert(this === THIS); | ||
@@ -106,19 +104,19 @@ }); | ||
| describe("With #caught", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "in an immediately trapped catch handler", function() { | ||
| return fulfilled().bind(THIS).then(function(){ | ||
| describe('With #caught', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('in an immediately trapped catch handler', function() { | ||
| return fulfilled().bind(THIS).then(function() { | ||
| assert(THIS === this); | ||
| var a; | ||
| a.b(); | ||
| }).caught(Error, function(e){ | ||
| }).caught(Error, function(e) { | ||
| assert(THIS === this); | ||
| }); | ||
| }); | ||
| specify( "in a later trapped catch handler", function() { | ||
| return fulfilled().bind(THIS).then(function(){ | ||
| specify('in a later trapped catch handler', function() { | ||
| return fulfilled().bind(THIS).then(function() { | ||
| throw new CustomError1(); | ||
| }).caught(CustomError2, assert.fail) | ||
| .caught(CustomError1, function(e){ | ||
| assert( THIS === this); | ||
| .caught(CustomError1, function(e) { | ||
| assert(THIS === this); | ||
| }); | ||
@@ -130,4 +128,4 @@ }); | ||
| describe("With .try promises", function() { | ||
| specify("this should refer to the bound object", function() { | ||
| describe('With .try promises', function() { | ||
| specify('this should refer to the bound object', function() { | ||
| return Promise.bind(THIS).constructor.try(function() { | ||
@@ -141,3 +139,3 @@ assert(this !== THIS); | ||
| }); | ||
| specify("explicit context should override", function() { | ||
| specify('explicit context should override', function() { | ||
| var NOTTHIS = {}; | ||
@@ -155,4 +153,4 @@ return Promise.bind(THIS).constructor.try(function() { | ||
| describe("With .method promises", function() { | ||
| specify("this should refer to the bound object", function() { | ||
| describe('With .method promises', function() { | ||
| specify('this should refer to the bound object', function() { | ||
| var f = Promise.bind(THIS).constructor.method(function() { | ||
@@ -167,3 +165,3 @@ assert(this !== THIS); | ||
| }); | ||
| specify("explicit context should override", function() { | ||
| specify('explicit context should override', function() { | ||
| var NOTTHIS = {}; | ||
@@ -182,4 +180,4 @@ var f = Promise.bind(THIS).constructor.method(function() { | ||
| describe("With .guard promises", function() { | ||
| specify("this should refer to the bound object", function() { | ||
| describe('With .guard promises', function() { | ||
| specify('this should refer to the bound object', function() { | ||
| var f = Promise.bind(THIS).constructor.guard(1, function() { | ||
@@ -194,3 +192,3 @@ assert(this !== THIS); | ||
| }); | ||
| specify("explicit context should override", function() { | ||
| specify('explicit context should override', function() { | ||
| var NOTTHIS = {}; | ||
@@ -209,6 +207,6 @@ var f = Promise.bind(THIS).constructor.guard(1, function() { | ||
| describe("With #get promises", function(){ | ||
| specify("this should refer to the bound object", function() { | ||
| return fulfilled({key: "value"}).bind(THIS).get("key").then(function(val){ | ||
| assert(val === "value"); | ||
| describe('With #get promises', function() { | ||
| specify('this should refer to the bound object', function() { | ||
| return fulfilled({key: 'value'}).bind(THIS).get('key').then(function(val) { | ||
| assert(val === 'value'); | ||
| assert(this === THIS); | ||
@@ -220,6 +218,6 @@ }); | ||
| describe("With #call promises", function(){ | ||
| specify("this should refer to the bound object", function() { | ||
| return fulfilled({key: function(){return "value";}}).bind(THIS).call("key").then(function(val){ | ||
| assert(val === "value"); | ||
| describe('With #call promises', function() { | ||
| specify('this should refer to the bound object', function() { | ||
| return fulfilled({key: function() {return 'value';}}).bind(THIS).call('key').then(function(val) { | ||
| assert(val === 'value'); | ||
| assert(this === THIS); | ||
@@ -231,6 +229,6 @@ }); | ||
| describe("With #return promises", function(){ | ||
| specify("this should refer to the bound object", function() { | ||
| return fulfilled().bind(THIS).return("value").then(function(val){ | ||
| assert(val === "value"); | ||
| describe('With #return promises', function() { | ||
| specify('this should refer to the bound object', function() { | ||
| return fulfilled().bind(THIS).return('value').then(function(val) { | ||
| assert(val === 'value'); | ||
| assert(this === THIS); | ||
@@ -242,6 +240,6 @@ }); | ||
| describe("With #throw promises", function(){ | ||
| specify("this should refer to the bound object", function() { | ||
| return fulfilled().bind(THIS).throw("value").then(assert.fail, function(val){ | ||
| assert(val === "value"); | ||
| describe('With #throw promises', function() { | ||
| specify('this should refer to the bound object', function() { | ||
| return fulfilled().bind(THIS).throw('value').then(assert.fail, function(val) { | ||
| assert(val === 'value'); | ||
| assert(this === THIS); | ||
@@ -253,27 +251,27 @@ }); | ||
| describe("With #spread promises", function(){ | ||
| describe('With #spread promises', function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "when spreading immediate array", function() { | ||
| return fulfilled([1,2,3]).bind(THIS).spread(function(a, b, c){ | ||
| describe('this should refer to the bound object', function() { | ||
| specify('when spreading immediate array', function() { | ||
| return fulfilled([1, 2, 3]).bind(THIS).spread(function(a, b, c) { | ||
| assert(c === 3); | ||
| assert( this === THIS ); | ||
| assert(this === THIS); | ||
| }); | ||
| }); | ||
| specify( "when spreading eventual array", function() { | ||
| specify('when spreading eventual array', function() { | ||
| var d = pending(); | ||
| var promise = d.promise; | ||
| setTimeout(function(){ | ||
| d.resolve([1,2,3]); | ||
| setTimeout(function() { | ||
| d.resolve([1, 2, 3]); | ||
| }, 50); | ||
| return promise.bind(THIS).spread(function(a, b, c){ | ||
| return promise.bind(THIS).spread(function(a, b, c) { | ||
| assert(c === 3); | ||
| assert( this === THIS ); | ||
| assert(this === THIS); | ||
| }); | ||
| }); | ||
| specify( "when spreading eventual array of eventual values", function() { | ||
| specify('when spreading eventual array of eventual values', function() { | ||
| var d = pending(); | ||
| var promise = d.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| var d1 = pending(); | ||
@@ -289,3 +287,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -296,5 +294,5 @@ d2.resolve(2); | ||
| }, 50); | ||
| return promise.bind(THIS).spread(function(a, b, c){ | ||
| return promise.bind(THIS).spread(function(a, b, c) { | ||
| assert(c === 3); | ||
| assert( this === THIS ); | ||
| assert(this === THIS); | ||
| }); | ||
@@ -306,5 +304,5 @@ }); | ||
| describe("With .promisify", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify("on success", function() { | ||
| describe('With .promisify', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('on success', function() { | ||
| var obj = { foo: function(cb) { cb(null, this.bar); }, bar: 42 }; | ||
@@ -317,3 +315,3 @@ var foo = Promise.bind(THIS).constructor.promisify(obj.foo, false, obj); | ||
| }); | ||
| specify("on failure", function() { | ||
| specify('on failure', function() { | ||
| var obj = { foo: function(cb) { cb(this.bar); }, bar: 42 }; | ||
@@ -329,10 +327,10 @@ var foo = Promise.bind(THIS).constructor.promisify(obj.foo, false, obj); | ||
| describe("With #nodify", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "when the callback succeeeds", function(done) { | ||
| fulfilled(3).bind(THIS).nodify(function(err, success){ | ||
| describe('With #nodify', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('when the callback succeeeds', function(done) { | ||
| fulfilled(3).bind(THIS).nodify(function(err, success) { | ||
| try { | ||
| assert( err === null ); | ||
| assert( success === 3 ); | ||
| assert( this === THIS ); | ||
| assert(err === null); | ||
| assert(success === 3); | ||
| assert(this === THIS); | ||
| done(); | ||
@@ -344,7 +342,7 @@ } catch (e) { | ||
| }); | ||
| specify( "when the callback errs", function(done) { | ||
| rejected(3).bind(THIS).nodify(function(err, success){ | ||
| specify('when the callback errs', function(done) { | ||
| rejected(3).bind(THIS).nodify(function(err, success) { | ||
| try { | ||
| assert( err === 3 ); | ||
| assert( this === THIS ); | ||
| assert(err === 3); | ||
| assert(this === THIS); | ||
| done(); | ||
@@ -360,12 +358,12 @@ } catch (e) { | ||
| describe("With #map", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "inside the mapper with immediate values", function() { | ||
| return fulfilled([1,2,3]).bind(THIS).map(function(v, i){ | ||
| if( i === 2 ) { | ||
| assert( this === THIS ); | ||
| describe('With #map', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('inside the mapper with immediate values', function() { | ||
| return fulfilled([1, 2, 3]).bind(THIS).map(function(v, i) { | ||
| if (i === 2) { | ||
| assert(this === THIS); | ||
| } | ||
| }); | ||
| }); | ||
| specify( "inside the mapper with eventual values", function() { | ||
| specify('inside the mapper with eventual values', function() { | ||
| var d1 = pending(); | ||
@@ -380,3 +378,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -387,5 +385,5 @@ d2.resolve(2); | ||
| return fulfilled([p1, p2, p3]).bind(THIS).map(function(v, i){ | ||
| if( i === 2 ) { | ||
| assert( this === THIS ); | ||
| return fulfilled([p1, p2, p3]).bind(THIS).map(function(v, i) { | ||
| if (i === 2) { | ||
| assert(this === THIS); | ||
| } | ||
@@ -395,6 +393,6 @@ }); | ||
| specify( "after the mapper with immediate values", function() { | ||
| return fulfilled([1,2,3]).bind(THIS).map(function(){ | ||
| specify('after the mapper with immediate values', function() { | ||
| return fulfilled([1, 2, 3]).bind(THIS).map(function() { | ||
| return 1; | ||
| }).then(function(){ | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
@@ -404,3 +402,3 @@ }); | ||
| specify( "after the mapper with eventual values", function() { | ||
| specify('after the mapper with eventual values', function() { | ||
| var d1 = pending(); | ||
@@ -415,3 +413,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -422,21 +420,21 @@ d2.resolve(2); | ||
| return fulfilled([p1, p2, p3]).bind(THIS).map(function(){ | ||
| return fulfilled([p1, p2, p3]).bind(THIS).map(function() { | ||
| return 1; | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
| }); | ||
| specify( "after the mapper with immediate values when the map returns promises", function() { | ||
| specify('after the mapper with immediate values when the map returns promises', function() { | ||
| var d1 = pending(); | ||
| var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
| }, 50); | ||
| return fulfilled([1,2,3]).bind(THIS).map(function(){ | ||
| return fulfilled([1, 2, 3]).bind(THIS).map(function() { | ||
| return p1; | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
@@ -446,18 +444,18 @@ }); | ||
| describe("this should not refer to the bound object", function() { | ||
| specify( "in the promises created within the handler", function() { | ||
| describe('this should not refer to the bound object', function() { | ||
| specify('in the promises created within the handler', function() { | ||
| var d1 = pending(); | ||
| var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
| }, 50); | ||
| return fulfilled([1,2,3]).bind(THIS).map(function(){ | ||
| return p1.then(function(){ | ||
| assert( this !== THIS ); | ||
| return fulfilled([1, 2, 3]).bind(THIS).map(function() { | ||
| return p1.then(function() { | ||
| assert(this !== THIS); | ||
| return 1; | ||
| }); | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
@@ -468,12 +466,12 @@ }); | ||
| describe("With #reduce", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "inside the reducer with immediate values", function() { | ||
| return fulfilled([1,2,3]).bind(THIS).reduce(function(prev, v, i){ | ||
| if( i === 2 ) { | ||
| assert( this === THIS ); | ||
| describe('With #reduce', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('inside the reducer with immediate values', function() { | ||
| return fulfilled([1, 2, 3]).bind(THIS).reduce(function(prev, v, i) { | ||
| if (i === 2) { | ||
| assert(this === THIS); | ||
| } | ||
| }); | ||
| }); | ||
| specify( "inside the reducer with eventual values", function() { | ||
| specify('inside the reducer with eventual values', function() { | ||
| var d1 = pending(); | ||
@@ -488,3 +486,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -495,5 +493,5 @@ d2.resolve(2); | ||
| return fulfilled([p1, p2, p3]).bind(THIS).reduce(function(prev, v, i){ | ||
| if( i === 2 ) { | ||
| assert( this === THIS ); | ||
| return fulfilled([p1, p2, p3]).bind(THIS).reduce(function(prev, v, i) { | ||
| if (i === 2) { | ||
| assert(this === THIS); | ||
| } | ||
@@ -503,6 +501,6 @@ }); | ||
| specify( "after the reducer with immediate values", function() { | ||
| return fulfilled([1,2,3]).bind(THIS).reduce(function(){ | ||
| specify('after the reducer with immediate values', function() { | ||
| return fulfilled([1, 2, 3]).bind(THIS).reduce(function() { | ||
| return 1; | ||
| }).then(function(){ | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
@@ -512,3 +510,3 @@ }); | ||
| specify( "after the reducer with eventual values", function() { | ||
| specify('after the reducer with eventual values', function() { | ||
| var d1 = pending(); | ||
@@ -523,3 +521,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -530,21 +528,21 @@ d2.resolve(2); | ||
| return fulfilled([p1, p2, p3]).bind(THIS).reduce(function(){ | ||
| return fulfilled([p1, p2, p3]).bind(THIS).reduce(function() { | ||
| return 1; | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
| }); | ||
| specify( "after the reducer with immediate values when the reducer returns promise", function() { | ||
| specify('after the reducer with immediate values when the reducer returns promise', function() { | ||
| var d1 = pending(); | ||
| var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
| }, 50); | ||
| return fulfilled([1,2,3]).bind(THIS).reduce(function(){ | ||
| return fulfilled([1, 2, 3]).bind(THIS).reduce(function() { | ||
| return p1; | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
@@ -554,18 +552,18 @@ }); | ||
| describe("this should not refer to the bound object", function() { | ||
| specify( "in the promises created within the handler", function() { | ||
| describe('this should not refer to the bound object', function() { | ||
| specify('in the promises created within the handler', function() { | ||
| var d1 = pending(); | ||
| var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
| }, 50); | ||
| return fulfilled([1,2,3]).bind(THIS).reduce(function(){ | ||
| return p1.then(function(){ | ||
| assert( this !== THIS ); | ||
| return fulfilled([1, 2, 3]).bind(THIS).reduce(function() { | ||
| return p1.then(function() { | ||
| assert(this !== THIS); | ||
| return 1; | ||
| }); | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
@@ -577,12 +575,12 @@ }); | ||
| describe("With #reduceRight", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "inside the reducer with immediate values", function() { | ||
| return fulfilled([1,2,3]).bind(THIS).reduceRight(function(prev, v, i){ | ||
| if( i === 2 ) { | ||
| assert( this === THIS ); | ||
| describe('With #reduceRight', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('inside the reducer with immediate values', function() { | ||
| return fulfilled([1, 2, 3]).bind(THIS).reduceRight(function(prev, v, i) { | ||
| if (i === 2) { | ||
| assert(this === THIS); | ||
| } | ||
| }); | ||
| }); | ||
| specify( "inside the reducer with eventual values", function() { | ||
| specify('inside the reducer with eventual values', function() { | ||
| var d1 = pending(); | ||
@@ -597,3 +595,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -606,4 +604,4 @@ d2.resolve(2); | ||
| reduceRight(function(prev, v, i) { | ||
| if( i === 2 ) { | ||
| assert( this === THIS ); | ||
| if (i === 2) { | ||
| assert(this === THIS); | ||
| } | ||
@@ -613,6 +611,6 @@ }); | ||
| specify( "after the reducer with immediate values", function() { | ||
| return fulfilled([1,2,3]).bind(THIS).reduceRight(function(){ | ||
| specify('after the reducer with immediate values', function() { | ||
| return fulfilled([1, 2, 3]).bind(THIS).reduceRight(function() { | ||
| return 1; | ||
| }).then(function(){ | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
@@ -622,3 +620,3 @@ }); | ||
| specify( "after the reducer with eventual values", function() { | ||
| specify('after the reducer with eventual values', function() { | ||
| var d1 = pending(); | ||
@@ -633,3 +631,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -640,21 +638,21 @@ d2.resolve(2); | ||
| return fulfilled([p1, p2, p3]).bind(THIS).reduceRight(function(){ | ||
| return fulfilled([p1, p2, p3]).bind(THIS).reduceRight(function() { | ||
| return 1; | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
| }); | ||
| specify( "after the reducer with immediate values when the reducer returns promise", function() { | ||
| specify('after the reducer with immediate values when the reducer returns promise', function() { | ||
| var d1 = pending(); | ||
| var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
| }, 50); | ||
| return fulfilled([1,2,3]).bind(THIS).reduceRight(function(){ | ||
| return fulfilled([1, 2, 3]).bind(THIS).reduceRight(function() { | ||
| return p1; | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
@@ -664,18 +662,18 @@ }); | ||
| describe("this should not refer to the bound object", function() { | ||
| specify( "in the promises created within the handler", function() { | ||
| describe('this should not refer to the bound object', function() { | ||
| specify('in the promises created within the handler', function() { | ||
| var d1 = pending(); | ||
| var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
| }, 50); | ||
| return fulfilled([1,2,3]).bind(THIS).reduceRight(function(){ | ||
| return p1.then(function(){ | ||
| assert( this !== THIS ); | ||
| return fulfilled([1, 2, 3]).bind(THIS).reduceRight(function() { | ||
| return p1.then(function() { | ||
| assert(this !== THIS); | ||
| return 1; | ||
| }); | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
@@ -687,11 +685,11 @@ }); | ||
| describe("With #all", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "after all with immediate values", function() { | ||
| return fulfilled([1,2,3]).bind(THIS).all().then(function(v){ | ||
| describe('With #all', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('after all with immediate values', function() { | ||
| return fulfilled([1, 2, 3]).bind(THIS).all().then(function(v) { | ||
| assert(v.length === 3); | ||
| assert( this === THIS ); | ||
| assert(this === THIS); | ||
| }); | ||
| }); | ||
| specify( "after all with eventual values", function() { | ||
| specify('after all with eventual values', function() { | ||
| var d1 = pending(); | ||
@@ -706,3 +704,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -713,5 +711,5 @@ d2.resolve(2); | ||
| return fulfilled([p1, p2, p3]).bind(THIS).all().then(function(v){ | ||
| return fulfilled([p1, p2, p3]).bind(THIS).all().then(function(v) { | ||
| assert(v.length === 3); | ||
| assert( this === THIS ); | ||
| assert(this === THIS); | ||
| }); | ||
@@ -721,18 +719,18 @@ }); | ||
| describe("this should not refer to the bound object", function() { | ||
| specify( "in the promises created within the handler", function() { | ||
| describe('this should not refer to the bound object', function() { | ||
| specify('in the promises created within the handler', function() { | ||
| var d1 = pending(); | ||
| var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
| }, 50); | ||
| return fulfilled([1,2,3]).bind(THIS).all(function(){ | ||
| return Promise.all([p1]).then(function(){ | ||
| assert( this !== THIS ); | ||
| return fulfilled([1, 2, 3]).bind(THIS).all(function() { | ||
| return Promise.all([p1]).then(function() { | ||
| assert(this !== THIS); | ||
| return 1; | ||
| }); | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
@@ -744,11 +742,11 @@ }); | ||
| describe("With .join", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "after join with immediate values", function() { | ||
| return Promise.bind(THIS).constructor.join(1, 2, 3).then(function(v){ | ||
| describe('With .join', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('after join with immediate values', function() { | ||
| return Promise.bind(THIS).constructor.join(1, 2, 3).then(function(v) { | ||
| assert(v.length === 3); | ||
| assert( this === THIS ); | ||
| assert(this === THIS); | ||
| }); | ||
| }); | ||
| specify( "after join with eventual values", function() { | ||
| specify('after join with eventual values', function() { | ||
| var d1 = pending(); | ||
@@ -763,3 +761,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -770,5 +768,5 @@ d2.resolve(2); | ||
| return Promise.bind(THIS).constructor.join(p1, p2, p3).then(function(v){ | ||
| return Promise.bind(THIS).constructor.join(p1, p2, p3).then(function(v) { | ||
| assert(v.length === 3); | ||
| assert( this === THIS ); | ||
| assert(this === THIS); | ||
| }); | ||
@@ -778,18 +776,18 @@ }); | ||
| describe("this should not refer to the bound object", function() { | ||
| specify( "in the promises created within the handler", function() { | ||
| describe('this should not refer to the bound object', function() { | ||
| specify('in the promises created within the handler', function() { | ||
| var d1 = pending(); | ||
| var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
| }, 50); | ||
| return Promise.bind(THIS).constructor.join(1, 2, 3).then(function(){ | ||
| return Promise.all([p1]).then(function(){ | ||
| assert( this !== THIS ); | ||
| return Promise.bind(THIS).constructor.join(1, 2, 3).then(function() { | ||
| return Promise.all([p1]).then(function() { | ||
| assert(this !== THIS); | ||
| return 1; | ||
| }); | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
@@ -801,11 +799,11 @@ }); | ||
| describe("With #race", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "after race with immediate values", function() { | ||
| return fulfilled([1,2,3]).bind(THIS).race().then(function(v){ | ||
| assert( v === 1 ); | ||
| assert( this === THIS ); | ||
| describe('With #race', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('after race with immediate values', function() { | ||
| return fulfilled([1, 2, 3]).bind(THIS).race().then(function(v) { | ||
| assert(v === 1); | ||
| assert(this === THIS); | ||
| }); | ||
| }); | ||
| specify( "after race with eventual values", function() { | ||
| specify('after race with eventual values', function() { | ||
| var d1 = pending(); | ||
@@ -820,3 +818,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -827,5 +825,5 @@ d2.resolve(2); | ||
| return fulfilled([p1, p2, p3]).bind(THIS).race().then(function(v){ | ||
| return fulfilled([p1, p2, p3]).bind(THIS).race().then(function(v) { | ||
| assert(v === 1); | ||
| assert( this === THIS ); | ||
| assert(this === THIS); | ||
| }); | ||
@@ -835,18 +833,18 @@ }); | ||
| describe("this should not refer to the bound object", function() { | ||
| specify( "in the promises created within the handler", function() { | ||
| describe('this should not refer to the bound object', function() { | ||
| specify('in the promises created within the handler', function() { | ||
| var d1 = pending(); | ||
| var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
| }, 50); | ||
| return fulfilled([1,2,3]).bind(THIS).race(function(){ | ||
| return Promise.race([p1]).then(function(){ | ||
| assert( this !== THIS ); | ||
| return fulfilled([1, 2, 3]).bind(THIS).race(function() { | ||
| return Promise.race([p1]).then(function() { | ||
| assert(this !== THIS); | ||
| return 1; | ||
| }); | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
@@ -858,11 +856,11 @@ }); | ||
| describe("With #props", function() { | ||
| describe("this should refer to the bound object", function() { | ||
| specify( "after props with immediate values", function() { | ||
| return fulfilled([1,2,3]).bind(THIS).props().then(function(v){ | ||
| describe('With #props', function() { | ||
| describe('this should refer to the bound object', function() { | ||
| specify('after props with immediate values', function() { | ||
| return fulfilled([1, 2, 3]).bind(THIS).props().then(function(v) { | ||
| assert(v[2] === 3); | ||
| assert( this === THIS ); | ||
| assert(this === THIS); | ||
| }); | ||
| }); | ||
| specify( "after props with eventual values", function() { | ||
| specify('after props with eventual values', function() { | ||
| var d1 = pending(); | ||
@@ -877,3 +875,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -884,5 +882,5 @@ d2.resolve(2); | ||
| return fulfilled([p1, p2, p3]).bind(THIS).props().then(function(v){ | ||
| return fulfilled([p1, p2, p3]).bind(THIS).props().then(function(v) { | ||
| assert(v[2] === 3); | ||
| assert( this === THIS ); | ||
| assert(this === THIS); | ||
| }); | ||
@@ -892,18 +890,18 @@ }); | ||
| describe("this should not refer to the bound object", function() { | ||
| specify( "in the promises created within the handler", function() { | ||
| describe('this should not refer to the bound object', function() { | ||
| specify('in the promises created within the handler', function() { | ||
| var d1 = pending(); | ||
| var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
| }, 50); | ||
| return fulfilled([1,2,3]).bind(THIS).props(function(){ | ||
| return Promise.settle([p1]).then(function(){ | ||
| assert( this !== THIS ); | ||
| return fulfilled([1, 2, 3]).bind(THIS).props(function() { | ||
| return Promise.settle([p1]).then(function() { | ||
| assert(this !== THIS); | ||
| return 1; | ||
| }); | ||
| }).then(function(){ | ||
| assert( this === THIS ); | ||
| }).then(function() { | ||
| assert(this === THIS); | ||
| }); | ||
@@ -914,3 +912,3 @@ }); | ||
| specify("should not get confused", function() { | ||
| specify('should not get confused', function() { | ||
| var a = {}; | ||
@@ -921,15 +919,15 @@ var b = {}; | ||
| return Promise.bind(a).then(function(){ | ||
| assert( this === a ); | ||
| return Promise.bind(a).then(function() { | ||
| assert(this === a); | ||
| ++dones; | ||
| }).bind(b).then(function(){ | ||
| assert( this === b ); | ||
| }).bind(b).then(function() { | ||
| assert(this === b); | ||
| ++dones; | ||
| }).bind(c).then(function(){ | ||
| assert( this === c ); | ||
| }).bind(c).then(function() { | ||
| assert(this === c); | ||
| ++dones; | ||
| }).then(function() { | ||
| assert( dones === 3 ); | ||
| assert(dones === 3); | ||
| }); | ||
| }); | ||
| }); |
+124
-123
@@ -1,5 +0,6 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -10,3 +11,3 @@ var fulfilled = Promise.resolve.bind(Promise); | ||
| var CustomError = function(){}; | ||
| var CustomError = function() {}; | ||
| CustomError.prototype = new Error(); | ||
@@ -31,5 +32,5 @@ | ||
| describe("A promise handler that throws a TypeError must be caught", function() { | ||
| describe('A promise handler that throws a TypeError must be caught', function() { | ||
| specify("in a middle.caught filter", function() { | ||
| specify('in a middle.caught filter', function() { | ||
| var a = pending(); | ||
@@ -40,9 +41,9 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| a.b.c.d(); | ||
| }).caught(SyntaxError, function(e){ | ||
| }).caught(SyntaxError, function(e) { | ||
| assert.fail(); | ||
| }).caught(TypeError, function(e){ | ||
| }).caught(TypeError, function(e) { | ||
| caught = true; | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| assert.fail(); | ||
@@ -55,3 +56,3 @@ }).then(function() { | ||
| specify("in a generic.caught filter that comes first", function() { | ||
| specify('in a generic.caught filter that comes first', function() { | ||
| var a = pending(); | ||
@@ -62,9 +63,9 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| a.b.c.d(); | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| caught = true; | ||
| }).caught(SyntaxError, function(e){ | ||
| }).caught(SyntaxError, function(e) { | ||
| assert.fail(); | ||
| }).caught(TypeError, function(e){ | ||
| }).caught(TypeError, function(e) { | ||
| assert.fail(); | ||
@@ -76,3 +77,3 @@ }).then(function() { | ||
| specify("in an explicitly generic.caught filter that comes first", function() { | ||
| specify('in an explicitly generic.caught filter that comes first', function() { | ||
| var a = pending(); | ||
@@ -83,9 +84,9 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| a.b.c.d(); | ||
| }).caught(Error, function(e){ | ||
| }).caught(Error, function(e) { | ||
| caught = true; | ||
| }).caught(SyntaxError, function(e){ | ||
| }).caught(SyntaxError, function(e) { | ||
| assert.fail(); | ||
| }).caught(Promise.TypeError, function(e){ | ||
| }).caught(Promise.TypeError, function(e) { | ||
| assert.fail(); | ||
@@ -97,3 +98,3 @@ }).then(function() { | ||
| specify("in a specific handler after thrown in generic", function() { | ||
| specify('in a specific handler after thrown in generic', function() { | ||
| var a = pending(); | ||
@@ -104,11 +105,11 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| a.b.c.d(); | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| throw e; | ||
| }).caught(SyntaxError, function(e){ | ||
| }).caught(SyntaxError, function(e) { | ||
| assert.fail(); | ||
| }).caught(TypeError, function(e){ | ||
| }).caught(TypeError, function(e) { | ||
| caught = true; | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| assert.fail(); | ||
@@ -121,3 +122,3 @@ }).then(function() { | ||
| specify("in a multi-filter handler", function() { | ||
| specify('in a multi-filter handler', function() { | ||
| var a = pending(); | ||
@@ -128,7 +129,7 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| a.b.c.d(); | ||
| }).caught(SyntaxError, TypeError, function(e){ | ||
| }).caught(SyntaxError, TypeError, function(e) { | ||
| caught = true; | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| assert.fail(); | ||
@@ -141,3 +142,3 @@ }).then(function() { | ||
| specify("in a specific handler after non-matching multi.caught handler", function() { | ||
| specify('in a specific handler after non-matching multi.caught handler', function() { | ||
| var a = pending(); | ||
@@ -148,9 +149,9 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| a.b.c.d(); | ||
| }).caught(SyntaxError, CustomError, function(e){ | ||
| }).caught(SyntaxError, CustomError, function(e) { | ||
| assert.fail(); | ||
| }).caught(TypeError, function(e){ | ||
| }).caught(TypeError, function(e) { | ||
| caught = true; | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| assert.fail(); | ||
@@ -165,5 +166,5 @@ }).then(function() { | ||
| describe("A promise handler that throws a custom error", function() { | ||
| describe('A promise handler that throws a custom error', function() { | ||
| specify( "Is filtered if inheritance was done even remotely properly", function() { | ||
| specify('Is filtered if inheritance was done even remotely properly', function() { | ||
| var a = pending(); | ||
@@ -175,10 +176,10 @@ var b = new CustomError(); | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| throw b; | ||
| }).caught(SyntaxError, function(e){ | ||
| }).caught(SyntaxError, function(e) { | ||
| assert.fail(); | ||
| }).caught(TypeError, function(e){ | ||
| }).caught(TypeError, function(e) { | ||
| assert.fail(); | ||
| }).caught(CustomError, function(e){ | ||
| assert.equal( e, b ); | ||
| }).caught(CustomError, function(e) { | ||
| assert.equal(e, b); | ||
| caught = true; | ||
@@ -190,3 +191,3 @@ }).then(function() { | ||
| specify( "Is filtered along with built-in errors", function() { | ||
| specify('Is filtered along with built-in errors', function() { | ||
| var a = pending(); | ||
@@ -198,5 +199,5 @@ var b = new CustomError(); | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| throw b; | ||
| }).caught(TypeError, SyntaxError, CustomError, function(e){ | ||
| }).caught(TypeError, SyntaxError, CustomError, function(e) { | ||
| caught = true; | ||
@@ -211,4 +212,4 @@ }).caught( | ||
| describe("A promise handler that throws a CustomError must be caught", function() { | ||
| specify("in a middle.caught filter", function() { | ||
| describe('A promise handler that throws a CustomError must be caught', function() { | ||
| specify('in a middle.caught filter', function() { | ||
| var a = pending(); | ||
@@ -219,9 +220,9 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| throw new CustomError(); | ||
| }).caught(SyntaxError, function(e){ | ||
| }).caught(SyntaxError, function(e) { | ||
| assert.fail(); | ||
| }).caught(CustomError, function(e){ | ||
| }).caught(CustomError, function(e) { | ||
| caught = true; | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| assert.fail(); | ||
@@ -234,3 +235,3 @@ }).then(function() { | ||
| specify("in a generic.caught filter that comes first", function() { | ||
| specify('in a generic.caught filter that comes first', function() { | ||
| var a = pending(); | ||
@@ -241,9 +242,9 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| throw new CustomError(); | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| caught = true; | ||
| }).caught(SyntaxError, function(e){ | ||
| }).caught(SyntaxError, function(e) { | ||
| assert.fail(); | ||
| }).caught(CustomError, function(e){ | ||
| }).caught(CustomError, function(e) { | ||
| assert.fail(); | ||
@@ -255,3 +256,3 @@ }).then(function() { | ||
| specify("in an explicitly generic.caught filter that comes first", function() { | ||
| specify('in an explicitly generic.caught filter that comes first', function() { | ||
| var a = pending(); | ||
@@ -262,9 +263,9 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| throw new CustomError(); | ||
| }).caught(Error, function(e){ | ||
| }).caught(Error, function(e) { | ||
| caught = true; | ||
| }).caught(SyntaxError, function(e){ | ||
| }).caught(SyntaxError, function(e) { | ||
| assert.fail(); | ||
| }).caught(CustomError, function(e){ | ||
| }).caught(CustomError, function(e) { | ||
| assert.fail(); | ||
@@ -276,3 +277,3 @@ }).then(function() { | ||
| specify("in a specific handler after thrown in generic", function() { | ||
| specify('in a specific handler after thrown in generic', function() { | ||
| var a = pending(); | ||
@@ -283,11 +284,11 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| throw new CustomError(); | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| throw e; | ||
| }).caught(SyntaxError, function(e){ | ||
| }).caught(SyntaxError, function(e) { | ||
| assert.fail(); | ||
| }).caught(CustomError, function(e){ | ||
| }).caught(CustomError, function(e) { | ||
| caught = true; | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| assert.fail(); | ||
@@ -300,3 +301,3 @@ }).then(function() { | ||
| specify("in a multi-filter handler", function() { | ||
| specify('in a multi-filter handler', function() { | ||
| var a = pending(); | ||
@@ -307,7 +308,7 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| throw new CustomError(); | ||
| }).caught(SyntaxError, CustomError, function(e){ | ||
| }).caught(SyntaxError, CustomError, function(e) { | ||
| caught = true; | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| assert.fail(); | ||
@@ -320,3 +321,3 @@ }).then(function() { | ||
| specify("in a specific handler after non-matching multi.caught handler", function() { | ||
| specify('in a specific handler after non-matching multi.caught handler', function() { | ||
| var a = pending(); | ||
@@ -327,9 +328,9 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| throw new CustomError(); | ||
| }).caught(SyntaxError, TypeError, function(e){ | ||
| }).caught(SyntaxError, TypeError, function(e) { | ||
| assert.fail(); | ||
| }).caught(CustomError, function(e){ | ||
| }).caught(CustomError, function(e) { | ||
| caught = true; | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| assert.fail(); | ||
@@ -343,5 +344,5 @@ }).then(function() { | ||
| describe("A promise handler that is caught in a filter", function() { | ||
| describe('A promise handler that is caught in a filter', function() { | ||
| specify( "is continued normally after returning a promise in filter", function() { | ||
| specify('is continued normally after returning a promise in filter', function() { | ||
| var a = pending(); | ||
@@ -354,18 +355,18 @@ var c = pending(); | ||
| return a.promise.then(function(v){ | ||
| assert.equal( v, 3 ); | ||
| return a.promise.then(function(v) { | ||
| assert.equal(v, 3); | ||
| throw b; | ||
| }).caught(SyntaxError, function(e){ | ||
| }).caught(SyntaxError, function(e) { | ||
| assert.fail(); | ||
| }).caught(TypeError, function(e){ | ||
| }).caught(TypeError, function(e) { | ||
| assert.fail(); | ||
| }).caught(CustomError, function(e){ | ||
| assert.equal( e, b ); | ||
| }).caught(CustomError, function(e) { | ||
| assert.equal(e, b); | ||
| return c.promise; | ||
| }).then(function(v) { | ||
| assert.equal( v, 3 ); | ||
| assert.equal(v, 3); | ||
| }); | ||
| }); | ||
| specify( "is continued normally after returning a promise in original handler", function() { | ||
| specify('is continued normally after returning a promise in original handler', function() { | ||
| var a = pending(); | ||
@@ -378,13 +379,13 @@ var c = pending(); | ||
| return a.promise.then(function(v){ | ||
| assert.equal( v, 3 ); | ||
| return a.promise.then(function(v) { | ||
| assert.equal(v, 3); | ||
| return c.promise; | ||
| }).caught(SyntaxError, function(e){ | ||
| }).caught(SyntaxError, function(e) { | ||
| assert.fail(); | ||
| }).caught(TypeError, function(e){ | ||
| }).caught(TypeError, function(e) { | ||
| assert.fail(); | ||
| }).caught(CustomError, function(e){ | ||
| }).caught(CustomError, function(e) { | ||
| assert.fail(); | ||
| }).then(function(v) { | ||
| assert.equal( v, 3 ); | ||
| assert.equal(v, 3); | ||
| }); | ||
@@ -394,5 +395,5 @@ }); | ||
| describe("A promise handler with a predicate filter", function() { | ||
| describe('A promise handler with a predicate filter', function() { | ||
| specify("will catch a thrown thing matching the filter", function() { | ||
| specify('will catch a thrown thing matching the filter', function() { | ||
| var a = pending(); | ||
@@ -403,7 +404,7 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| throw new Error("horrible invalid error string"); | ||
| }).caught(predicateFilter, function(e){ | ||
| return a.promise.then(function() { | ||
| throw new Error('horrible invalid error string'); | ||
| }).caught(predicateFilter, function(e) { | ||
| caught = true; | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| assert.fail(); | ||
@@ -415,3 +416,3 @@ }).then(function() { | ||
| specify("will NOT catch a thrown thing not matching the filter", function() { | ||
| specify('will NOT catch a thrown thing not matching the filter', function() { | ||
| var a = pending(); | ||
@@ -422,7 +423,7 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| throw new Error("horrible valid error string"); | ||
| }).caught(predicateFilter, function(e){ | ||
| return a.promise.then(function() { | ||
| throw new Error('horrible valid error string'); | ||
| }).caught(predicateFilter, function(e) { | ||
| assert.fail(); | ||
| }).caught(function(e){ | ||
| }).caught(function(e) { | ||
| caught = true; | ||
@@ -434,3 +435,3 @@ }).then(function() { | ||
| specify("will fail when a predicate is a bad error class", function() { | ||
| specify('will fail when a predicate is a bad error class', function() { | ||
| var a = pending(); | ||
@@ -441,9 +442,9 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| throw new Error("horrible custom error"); | ||
| }).caught(123, function(e){ | ||
| return a.promise.then(function() { | ||
| throw new Error('horrible custom error'); | ||
| }).caught(123, function(e) { | ||
| assert.fail(); | ||
| }).caught(TypeError, function(e){ | ||
| // Comment-out to show the TypeError stack | ||
| //console.error(e.stack); | ||
| }).caught(TypeError, function(e) { | ||
| // Uncomment to show the TypeError stack | ||
| // console.error(e.stack); | ||
| caught = true; | ||
@@ -455,3 +456,3 @@ }).then(function() { | ||
| specify("will catch a thrown undefiend", function(){ | ||
| specify('will catch a thrown undefiend', function() { | ||
| var a = pending(); | ||
@@ -462,7 +463,7 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| return a.promise.then(function() { | ||
| throw void 0; | ||
| }).caught(function(e) { return false; }, function(e) { | ||
| assert.fail(); | ||
| }).caught(predicatesUndefined, function(e){ | ||
| }).caught(predicatesUndefined, function(e) { | ||
| caught = true; | ||
@@ -476,3 +477,3 @@ }).caught(function(e) { | ||
| specify("will catch a thrown string", function(){ | ||
| specify('will catch a thrown string', function() { | ||
| var a = pending(); | ||
@@ -483,7 +484,7 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| throw "asd"; | ||
| return a.promise.then(function() { | ||
| throw 'asd'; | ||
| }).caught(function(e) { return false; }, function(e) { | ||
| assert.fail(); | ||
| }).caught(predicatesPrimitiveString, function(e){ | ||
| }).caught(predicatesPrimitiveString, function(e) { | ||
| caught = true; | ||
@@ -497,3 +498,3 @@ }).caught(function(e) { | ||
| specify("will fail when a predicate throws", function() { | ||
| specify('will fail when a predicate throws', function() { | ||
| var a = pending(); | ||
@@ -504,8 +505,8 @@ var caught = false; | ||
| return a.promise.then(function(){ | ||
| throw new CustomError("error happens"); | ||
| }).caught(function(e) { return e.f.g; }, function(e){ | ||
| return a.promise.then(function() { | ||
| throw new CustomError('error happens'); | ||
| }).caught(function(e) { return e.f.g; }, function(e) { | ||
| assert.fail(); | ||
| }).caught(TypeError, function(e){ | ||
| //console.error(e.stack); | ||
| }).caught(TypeError, function(e) { | ||
| // console.error(e.stack); | ||
| caught = true; | ||
@@ -512,0 +513,0 @@ }).caught(function(e) { |
+97
-97
@@ -1,5 +0,5 @@ | ||
| "use strict"; | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -10,114 +10,114 @@ var fulfilled = Promise.resolve.bind(Promise); | ||
| describe("Promise filter", function() { | ||
| describe('Promise filter', function() { | ||
| function ThrownError() {} | ||
| function ThrownError() {} | ||
| var arr = [1,2,3]; | ||
| var arr = [1, 2, 3]; | ||
| function assertArr(arr) { | ||
| assert(arr.length === 2); | ||
| assert(arr[0] === 1); | ||
| assert(arr[1] === 3); | ||
| } | ||
| function assertArr(arr) { | ||
| assert(arr.length === 2); | ||
| assert(arr[0] === 1); | ||
| assert(arr[1] === 3); | ||
| } | ||
| function assertErr(e) { | ||
| assert(e instanceof ThrownError); | ||
| } | ||
| function assertErr(e) { | ||
| assert(e instanceof ThrownError); | ||
| } | ||
| function assertFail() { | ||
| assert.fail(); | ||
| } | ||
| function assertFail() { | ||
| assert.fail(); | ||
| } | ||
| describe("should accept eventual booleans", function() { | ||
| specify("immediately fulfilled", function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return new Promise(function(r){ | ||
| r(v !== 2); | ||
| }); | ||
| }).then(assertArr); | ||
| describe('should accept eventual booleans', function() { | ||
| specify('immediately fulfilled', function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return new Promise(function(r) { | ||
| r(v !== 2); | ||
| }); | ||
| }).then(assertArr); | ||
| }); | ||
| specify("already fulfilled", function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return Promise.resolve(v !== 2); | ||
| }).then(assertArr); | ||
| }); | ||
| specify('already fulfilled', function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return Promise.resolve(v !== 2); | ||
| }).then(assertArr); | ||
| }); | ||
| specify("eventually fulfilled", function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return new Promise(function(r){ | ||
| setTimeout(function(){ | ||
| r(v !== 2); | ||
| }, 13); | ||
| }); | ||
| }).then(assertArr); | ||
| specify('eventually fulfilled', function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return new Promise(function(r) { | ||
| setTimeout(function() { | ||
| r(v !== 2); | ||
| }, 13); | ||
| }); | ||
| }).then(assertArr); | ||
| }); | ||
| specify("immediately rejected", function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return new Promise(function(v, r){ | ||
| r(new ThrownError()); | ||
| }); | ||
| }).then(assertFail, assertErr); | ||
| specify('immediately rejected', function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return new Promise(function(v, r) { | ||
| r(new ThrownError()); | ||
| }); | ||
| specify("already rejected", function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return Promise.reject(new ThrownError()); | ||
| }).then(assertFail, assertErr); | ||
| }).then(assertFail, assertErr); | ||
| }); | ||
| specify('already rejected', function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return Promise.reject(new ThrownError()); | ||
| }).then(assertFail, assertErr); | ||
| }); | ||
| specify('eventually rejected', function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return new Promise(function(v, r) { | ||
| setTimeout(function() { | ||
| r(new ThrownError()); | ||
| }, 13); | ||
| }); | ||
| specify("eventually rejected", function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return new Promise(function(v, r){ | ||
| setTimeout(function(){ | ||
| r(new ThrownError()); | ||
| }, 13); | ||
| }); | ||
| }).then(assertFail, assertErr); | ||
| }); | ||
| }).then(assertFail, assertErr); | ||
| }); | ||
| specify("immediately fulfilled thenable", function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return { | ||
| then: function(f, r) { | ||
| f(v !== 2); | ||
| } | ||
| }; | ||
| }).then(assertArr); | ||
| }); | ||
| specify("eventually fulfilled thenable", function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return { | ||
| then: function(f, r) { | ||
| setTimeout(function(){ | ||
| f(v !== 2); | ||
| }, 13); | ||
| } | ||
| }; | ||
| }).then(assertArr); | ||
| }); | ||
| specify('immediately fulfilled thenable', function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return { | ||
| then: function(f, r) { | ||
| f(v !== 2); | ||
| }, | ||
| }; | ||
| }).then(assertArr); | ||
| }); | ||
| specify('eventually fulfilled thenable', function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return { | ||
| then: function(f, r) { | ||
| setTimeout(function() { | ||
| f(v !== 2); | ||
| }, 13); | ||
| }, | ||
| }; | ||
| }).then(assertArr); | ||
| }); | ||
| specify("immediately rejected thenable", function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return { | ||
| then: function(f, r) { | ||
| r(new ThrownError()); | ||
| } | ||
| }; | ||
| }).then(assertFail, assertErr); | ||
| }); | ||
| specify("eventually rejected thenable", function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return { | ||
| then: function(f, r) { | ||
| setTimeout(function(){ | ||
| r(new ThrownError()); | ||
| }, 13); | ||
| } | ||
| }; | ||
| }).then(assertFail, assertErr); | ||
| }); | ||
| specify('immediately rejected thenable', function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return { | ||
| then: function(f, r) { | ||
| r(new ThrownError()); | ||
| }, | ||
| }; | ||
| }).then(assertFail, assertErr); | ||
| }); | ||
| specify('eventually rejected thenable', function() { | ||
| return Promise.filter(arr, function(v) { | ||
| return { | ||
| then: function(f, r) { | ||
| setTimeout(function() { | ||
| r(new ThrownError()); | ||
| }, 13); | ||
| }, | ||
| }; | ||
| }).then(assertFail, assertErr); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
+70
-69
@@ -1,10 +0,11 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| /* jshint evil:true */ | ||
| 'use strict'; | ||
| // bail if we're not running in node >= 0.11 | ||
| var node11 = parseInt(process.versions.node.split(".")[1], 10) >= 11; | ||
| // Bail if we're not running in node >= 0.11 | ||
| var node11 = parseInt(process.versions.node.split('.')[1], 10) >= 11; | ||
| if (!node11) { return; } | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -15,3 +16,3 @@ function get(arg) { | ||
| ful(arg); | ||
| } | ||
| }, | ||
| }; | ||
@@ -24,3 +25,3 @@ } | ||
| rej(arg); | ||
| } | ||
| }, | ||
| }; | ||
@@ -30,3 +31,3 @@ } | ||
| function delay() { | ||
| return new Promise(function(a){ | ||
| return new Promise(function(a) { | ||
| setTimeout(a, 15); | ||
@@ -36,15 +37,15 @@ }); | ||
| var error = new Error("asd"); | ||
| var error = new Error('asd'); | ||
| describe("Promise.async", function() { | ||
| describe("thenables", function() { | ||
| specify("when they fulfill, the yielded value should be that fulfilled value", function(){ | ||
| describe('Promise.async', function() { | ||
| describe('thenables', function() { | ||
| specify('when they fulfill, the yielded value should be that fulfilled value', function() { | ||
| return Promise.async(eval('(function*(){'+ | ||
| return Promise.async(eval('(function*(){' + | ||
| 'var a = yield get(3);'+ | ||
| 'assert.equal(a, 3);'+ | ||
| 'return 4;'+ | ||
| 'var a = yield get(3);' + | ||
| 'assert.equal(a, 3);' + | ||
| 'return 4;' + | ||
| '})'))().then(function(arg){ | ||
| '})'))().then(function(arg) { | ||
| assert.equal(arg, 4); | ||
@@ -58,7 +59,7 @@ }); | ||
| return Promise.async(eval('(function*(){'+ | ||
| 'var a = yield fail(error);'+ | ||
| 'assert.fail();'+ | ||
| return Promise.async(eval('(function*(){' + | ||
| 'var a = yield fail(error);' + | ||
| 'assert.fail();' + | ||
| '})'))().then(assert.fail, function(e){ | ||
| '})'))().then(assert.fail, function(e) { | ||
| assert.equal(e, error); | ||
@@ -69,12 +70,12 @@ }); | ||
| specify("when they reject, and the generator has try.caught, it should continue working normally", function() { | ||
| specify('when they reject, and the generator has try.caught, it should continue working normally', function() { | ||
| return Promise.async(eval('(function*(){'+ | ||
| 'try {'+ | ||
| ' var a = yield fail(error);'+ | ||
| '} catch(e) {'+ | ||
| ' return e;'+ | ||
| '}'+ | ||
| 'assert.fail();'+ | ||
| '})'))().then(function(v){ | ||
| return Promise.async(eval('(function*(){' + | ||
| 'try {' + | ||
| ' var a = yield fail(error);' + | ||
| '} catch(e) {' + | ||
| ' return e;' + | ||
| '}' + | ||
| 'assert.fail();' + | ||
| '})'))().then(function(v) { | ||
| assert.equal(v, error); | ||
@@ -85,9 +86,9 @@ }); | ||
| specify("when they fulfill but then throw, it should become rejection", function() { | ||
| specify('when they fulfill but then throw, it should become rejection', function() { | ||
| return Promise.async(eval('(function*(){'+ | ||
| 'var a = yield get(3);'+ | ||
| 'assert.equal(a, 3);'+ | ||
| 'throw error;'+ | ||
| '})'))().then(assert.fail, function(e){ | ||
| return Promise.async(eval('(function*(){' + | ||
| 'var a = yield get(3);' + | ||
| 'assert.equal(a, 3);' + | ||
| 'throw error;' + | ||
| '})'))().then(assert.fail, function(e) { | ||
| assert.equal(e, error); | ||
@@ -98,41 +99,41 @@ }); | ||
| describe("yield loop", function(){ | ||
| describe('yield loop', function() { | ||
| specify("should work", function() { | ||
| return Promise.async(eval('(function*() {'+ | ||
| 'var a = [1,2,3,4,5];'+ | ||
| specify('should work', function() { | ||
| return Promise.async(eval('(function*() {' + | ||
| 'var a = [1,2,3,4,5];' + | ||
| 'for( var i = 0, len = a.length; i < len; ++i ) {'+ | ||
| ' a[i] = yield get(a[i] * 2);'+ | ||
| '}'+ | ||
| 'for( var i = 0, len = a.length; i < len; ++i ) {' + | ||
| ' a[i] = yield get(a[i] * 2);' + | ||
| '}' + | ||
| 'return a;'+ | ||
| '})'))().then(function(arr){ | ||
| assert.deepEqual([2,4,6,8,10], arr); | ||
| 'return a;' + | ||
| '})'))().then(function(arr) { | ||
| assert.deepEqual([2, 4, 6, 8, 10], arr); | ||
| }); | ||
| }); | ||
| specify("inside yield should work", function() { | ||
| return Promise.async(eval('(function*() {'+ | ||
| 'var a = [1,2,3,4,5];'+ | ||
| specify('inside yield should work', function() { | ||
| return Promise.async(eval('(function*() {' + | ||
| 'var a = [1,2,3,4,5];' + | ||
| 'return yield Promise.all(a.map(function(v){'+ | ||
| ' return Promise.async(function *() {'+ | ||
| ' return yield get(v*2);'+ | ||
| ' })();'+ | ||
| '}));'+ | ||
| '})'))().then(function(arr){ | ||
| assert.deepEqual([2,4,6,8,10], arr); | ||
| 'return yield Promise.all(a.map(function(v){' + | ||
| ' return Promise.async(function *() {' + | ||
| ' return yield get(v*2);' + | ||
| ' })();' + | ||
| '}));' + | ||
| '})'))().then(function(arr) { | ||
| assert.deepEqual([2, 4, 6, 8, 10], arr); | ||
| }); | ||
| }); | ||
| specify("with simple map should work", function() { | ||
| return Promise.async(eval('(function*() {'+ | ||
| 'var a = [1,2,3,4,5];'+ | ||
| specify('with simple map should work', function() { | ||
| return Promise.async(eval('(function*() {' + | ||
| 'var a = [1,2,3,4,5];' + | ||
| 'return yield Promise.map(a, function(v){'+ | ||
| ' return Promise.resolve(get(v*2));'+ | ||
| '});'+ | ||
| '})'))().then(function(arr){ | ||
| assert.deepEqual([2,4,6,8,10], arr); | ||
| 'return yield Promise.map(a, function(v){' + | ||
| ' return Promise.resolve(get(v*2));' + | ||
| '});' + | ||
| '})'))().then(function(arr) { | ||
| assert.deepEqual([2, 4, 6, 8, 10], arr); | ||
| }); | ||
@@ -143,3 +144,3 @@ }); | ||
| describe("when using async as a method", function(){ | ||
| describe('when using async as a method', function() { | ||
@@ -150,4 +151,4 @@ function MyClass() { | ||
| MyClass.prototype.spawnGoblins = Promise.async(eval('(function*(){'+ | ||
| ' this.goblins = yield get(this.goblins+1);'+ | ||
| MyClass.prototype.spawnGoblins = Promise.async(eval('(function*(){' + | ||
| ' this.goblins = yield get(this.goblins+1);' + | ||
| '})')); | ||
@@ -160,5 +161,5 @@ | ||
| return Promise.join(a.spawnGoblins().then(function(){ | ||
| return Promise.join(a.spawnGoblins().then(function() { | ||
| return a.spawnGoblins(); | ||
| }), b.spawnGoblins()).then(function(){ | ||
| }), b.spawnGoblins()).then(function() { | ||
| assert.equal(a.goblins, 5); | ||
@@ -165,0 +166,0 @@ assert.equal(b.goblins, 4); |
+11
-8
@@ -1,5 +0,6 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| var assert = require('assert'); | ||
| require('../'); | ||
| var Promise = require('../'); | ||
@@ -11,3 +12,3 @@ var sentinel = {}; | ||
| var mkspy= function(calls) { | ||
| var mkspy = function(calls) { | ||
| return function spy() { | ||
@@ -20,7 +21,7 @@ var args = Array.prototype.slice.call(arguments); | ||
| describe('Promise.guard', function () { | ||
| describe('Promise.guard', function() { | ||
| it('should return a function', function() { | ||
| assert.equal(typeof Promise.guard(), 'function'); | ||
| // return a promise from all synchronous tests, for consistency | ||
| // Return a promise from all synchronous tests, for consistency | ||
| return Promise.resolve(); | ||
@@ -30,3 +31,5 @@ }); | ||
| it('should invoke condition', function() { | ||
| var condition, guarded, called = 0; | ||
| var condition; | ||
| var guarded; | ||
| var called = 0; | ||
@@ -41,3 +44,3 @@ condition = function() { called++; }; | ||
| // return a promise from all synchronous tests, for consistency | ||
| // Return a promise from all synchronous tests, for consistency | ||
| return Promise.resolve(); | ||
@@ -157,4 +160,4 @@ }); | ||
| return Promise.join(p1, p2, p3); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
+22
-22
@@ -1,5 +0,5 @@ | ||
| "use strict"; | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -13,3 +13,3 @@ var fulfilled = Promise.resolve.bind(Promise); | ||
| describe("Promise.method", function(){ | ||
| describe('Promise.method', function() { | ||
@@ -32,3 +32,3 @@ var thrower = Promise.method(function() { | ||
| specify("should reject when the function throws", function() { | ||
| specify('should reject when the function throws', function() { | ||
| var async = false; | ||
@@ -43,3 +43,3 @@ var p = thrower().then(assert.fail, function(e) { | ||
| specify("should throw when the function is not a function", function() { | ||
| specify('should throw when the function is not a function', function() { | ||
| try { | ||
@@ -49,10 +49,10 @@ Promise.method(null); | ||
| } | ||
| catch(e) { | ||
| catch (e) { | ||
| assert(e instanceof TypeError); | ||
| } | ||
| // return a promise from all synchronous tests, for consistency | ||
| // Return a promise from all synchronous tests, for consistency | ||
| return Promise.resolve(); | ||
| }); | ||
| specify("should call the function with the given receiver", function() { | ||
| specify('should call the function with the given receiver', function() { | ||
| var async = false; | ||
@@ -67,3 +67,3 @@ var p = receiver.call(obj).then(function(val) { | ||
| specify("should call the function with the given value", function() { | ||
| specify('should call the function with the given value', function() { | ||
| var async = false; | ||
@@ -78,7 +78,7 @@ var p = identity(obj).then(function(val) { | ||
| specify("should apply the function if given value is array", function() { | ||
| specify('should apply the function if given value is array', function() { | ||
| var async = false; | ||
| var p = array(1, 2, 3).then(function(val) { | ||
| assert(async); | ||
| assert.deepEqual(val, [1,2,3]); | ||
| assert.deepEqual(val, [1, 2, 3]); | ||
| }); | ||
@@ -89,12 +89,12 @@ async = true; | ||
| specify("should unwrap returned promise", function() { | ||
| specify('should unwrap returned promise', function() { | ||
| var d = pending(); | ||
| var p = Promise.method(function(){ | ||
| var p = Promise.method(function() { | ||
| return d.promise; | ||
| })().then(function(v){ | ||
| })().then(function(v) { | ||
| assert.deepEqual(v, 3); | ||
| }); | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d.resolve(3); | ||
@@ -105,10 +105,10 @@ }, 13); | ||
| specify("should unwrap returned thenable", function() { | ||
| return Promise.method(function(){ | ||
| specify('should unwrap returned thenable', function() { | ||
| return Promise.method(function() { | ||
| return { | ||
| then: function(f, v) { | ||
| f(3); | ||
| } | ||
| }, | ||
| }; | ||
| })().then(function(v){ | ||
| })().then(function(v) { | ||
| assert.deepEqual(v, 3); | ||
@@ -118,3 +118,3 @@ }); | ||
| specify("should unwrap this and arguments", function() { | ||
| specify('should unwrap this and arguments', function() { | ||
| var THIS = {}; | ||
@@ -127,3 +127,3 @@ var pThis = pending(); | ||
| var p = f.call(pThis.promise, fulfilled(42)); | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| pThis.resolve(THIS); | ||
@@ -130,0 +130,0 @@ }, 10); |
+112
-111
@@ -1,5 +0,6 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -9,3 +10,3 @@ var RejectionError = function() {}; | ||
| var erroneousNode = function(a, b, c, cb) { | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| cb(sentinelError); | ||
@@ -19,3 +20,3 @@ }, 10); | ||
| var successNode = function(a, b, c, cb) { | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| cb(null, sentinel); | ||
@@ -26,3 +27,3 @@ }, 10); | ||
| var successNodeMultipleValues = function(a, b, c, cb) { | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| cb(null, sentinel, sentinel, sentinel); | ||
@@ -50,14 +51,14 @@ }, 10); | ||
| var tprimitive = "Where is your stack now?"; | ||
| var throwsStrings = Promise.promisify(function(cb){ | ||
| var tprimitive = 'Where is your stack now?'; | ||
| var throwsStrings = Promise.promisify(function(cb) { | ||
| throw tprimitive; | ||
| }); | ||
| var errbacksStrings = Promise.promisify(function(cb){ | ||
| cb( tprimitive ); | ||
| var errbacksStrings = Promise.promisify(function(cb) { | ||
| cb(tprimitive); | ||
| }); | ||
| var errbacksStringsAsync = Promise.promisify(function(cb){ | ||
| setTimeout(function(){ | ||
| cb( tprimitive ); | ||
| var errbacksStringsAsync = Promise.promisify(function(cb) { | ||
| setTimeout(function() { | ||
| cb(tprimitive); | ||
| }, 13); | ||
@@ -69,32 +70,32 @@ }); | ||
| var successMulti = Promise.promisify(successNodeMultipleValues, true); | ||
| var successMulti2 = Promise.promisify(successNodeMultipleValues, ['a','b','c','d']); | ||
| var successMulti2 = Promise.promisify(successNodeMultipleValues, ['a', 'b', 'c', 'd']); | ||
| var syncError = Promise.promisify(syncErroneousNode); | ||
| var syncSuccess = Promise.promisify(syncSuccessNode); | ||
| var syncSuccessMulti = Promise.promisify(syncSuccessNodeMultipleValues, true); | ||
| var syncSuccessMulti2 = Promise.promisify(syncSuccessNodeMultipleValues, ['a','b','c','d']); | ||
| var syncSuccessMulti2 = Promise.promisify(syncSuccessNodeMultipleValues, ['a', 'b', 'c', 'd']); | ||
| describe("when calling promisified function it should ", function(){ | ||
| describe('when calling promisified function it should ', function() { | ||
| specify("return a promise that is pending", function() { | ||
| specify('return a promise that is pending', function() { | ||
| var pending = true; | ||
| var a = error(1,2,3); | ||
| var b = success(1,2,3); | ||
| var c = successMulti(1,2,3); | ||
| var d = successMulti2(1,2,3); | ||
| var a = error(1, 2, 3); | ||
| var b = success(1, 2, 3); | ||
| var c = successMulti(1, 2, 3); | ||
| var d = successMulti2(1, 2, 3); | ||
| a['finally'](function(){ pending=false; }); | ||
| b['finally'](function(){ pending=false; }); | ||
| c['finally'](function(){ pending=false; }); | ||
| d['finally'](function(){ pending=false; }); | ||
| a['finally'](function() { pending = false; }); | ||
| b['finally'](function() { pending = false; }); | ||
| c['finally'](function() { pending = false; }); | ||
| d['finally'](function() { pending = false; }); | ||
| assert.equal(pending, true); | ||
| return a.then(assert.fail, function() { /* caught */ }) | ||
| return a.then(assert.fail, function() { /* Caught */ }) | ||
| .return(b).return(c).return(d).return(); | ||
| }); | ||
| specify( "should use this if no receiver was given", function() { | ||
| specify('should use this if no receiver was given', function() { | ||
| var o = {}; | ||
| var fn = Promise.promisify(function(cb){ | ||
| var fn = Promise.promisify(function(cb) { | ||
@@ -106,3 +107,3 @@ cb(null, this === o); | ||
| return o.fn().then(function(val){ | ||
| return o.fn().then(function(val) { | ||
| assert(val); | ||
@@ -112,14 +113,14 @@ }); | ||
| specify("call future attached handlers later", function(done) { | ||
| var a = error(1,2,3); | ||
| var b = success(1,2,3); | ||
| var c = successMulti(1,2,3); | ||
| var c2 = successMulti2(1,2,3); | ||
| var d = syncError(1,2,3); | ||
| var e = syncSuccess(1,2,3); | ||
| var f = syncSuccessMulti(1,2,3); | ||
| var f2 = syncSuccessMulti2(1,2,3); | ||
| specify('call future attached handlers later', function(done) { | ||
| var a = error(1, 2, 3); | ||
| var b = success(1, 2, 3); | ||
| var c = successMulti(1, 2, 3); | ||
| var c2 = successMulti2(1, 2, 3); | ||
| var d = syncError(1, 2, 3); | ||
| var e = syncSuccess(1, 2, 3); | ||
| var f = syncSuccessMulti(1, 2, 3); | ||
| var f2 = syncSuccessMulti2(1, 2, 3); | ||
| var calls = 0; | ||
| function donecall() { | ||
| if( (++calls) === 8 ) { | ||
| if ((++calls) === 8) { | ||
| done(); | ||
@@ -129,6 +130,6 @@ } | ||
| a.caught(function(){}); | ||
| d.caught(function(){}); | ||
| a.caught(function() {}); | ||
| d.caught(function() {}); | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| a.then(assert.fail, donecall); | ||
@@ -145,4 +146,4 @@ b.then(donecall, assert.fail); | ||
| specify("Reject with the synchronously caught reason", function() { | ||
| return thrower(1, 2, 3).then(assert.fail, function(e){ | ||
| specify('Reject with the synchronously caught reason', function() { | ||
| return thrower(1, 2, 3).then(assert.fail, function(e) { | ||
| assert(e === errToThrow); | ||
@@ -152,8 +153,8 @@ }); | ||
| specify("reject with the proper reason", function(done) { | ||
| var a = error(1,2,3); | ||
| var b = syncError(1,2,3); | ||
| specify('reject with the proper reason', function(done) { | ||
| var a = error(1, 2, 3); | ||
| var b = syncError(1, 2, 3); | ||
| var calls = 0; | ||
| function donecall() { | ||
| if( (++calls) === 2 ) { | ||
| if ((++calls) === 2) { | ||
| done(); | ||
@@ -163,8 +164,8 @@ } | ||
| a.caught(function(e){ | ||
| assert.equal( sentinelError, e); | ||
| a.caught(function(e) { | ||
| assert.equal(sentinelError, e); | ||
| donecall(); | ||
| }); | ||
| b.caught(function(e){ | ||
| assert.equal( sentinelError, e); | ||
| b.caught(function(e) { | ||
| assert.equal(sentinelError, e); | ||
| donecall(); | ||
@@ -174,34 +175,34 @@ }); | ||
| specify("fulfill with proper value(s)", function() { | ||
| var a = success(1,2,3); | ||
| var b = successMulti(1,2,3); | ||
| var b2 = successMulti2(1,2,3); | ||
| var c = syncSuccess(1,2,3); | ||
| var d = syncSuccessMulti(1,2,3); | ||
| var d2 = syncSuccessMulti2(1,2,3); | ||
| specify('fulfill with proper value(s)', function() { | ||
| var a = success(1, 2, 3); | ||
| var b = successMulti(1, 2, 3); | ||
| var b2 = successMulti2(1, 2, 3); | ||
| var c = syncSuccess(1, 2, 3); | ||
| var d = syncSuccessMulti(1, 2, 3); | ||
| var d2 = syncSuccessMulti2(1, 2, 3); | ||
| return Promise.join( | ||
| a.then(function( val ){ | ||
| a.then(function(val) { | ||
| assert.equal(val, sentinel); | ||
| }), | ||
| b.then(function( val ){ | ||
| assert.deepEqual( val, [sentinel, sentinel, sentinel] ); | ||
| b.then(function(val) { | ||
| assert.deepEqual(val, [sentinel, sentinel, sentinel]); | ||
| }), | ||
| b2.then(function( val ){ | ||
| assert.deepEqual( val, { a:sentinel, b:sentinel, c:sentinel, d:undefined } ); | ||
| b2.then(function(val) { | ||
| assert.deepEqual(val, { a: sentinel, b: sentinel, c: sentinel, d: undefined }); | ||
| }), | ||
| c.then(function( val ){ | ||
| c.then(function(val) { | ||
| assert.equal(val, sentinel); | ||
| }), | ||
| d.then(function( val ){ | ||
| assert.deepEqual( val, [sentinel, sentinel, sentinel] ); | ||
| d.then(function(val) { | ||
| assert.deepEqual(val, [sentinel, sentinel, sentinel]); | ||
| }), | ||
| d2.then(function( val ){ | ||
| assert.deepEqual( val, { a:sentinel, b:sentinel, c:sentinel, d:undefined } ); | ||
| d2.then(function(val) { | ||
| assert.deepEqual(val, { a: sentinel, b: sentinel, c: sentinel, d: undefined }); | ||
| }) | ||
@@ -216,3 +217,3 @@ | ||
| describe("with more than 5 arguments", function(){ | ||
| describe('with more than 5 arguments', function() { | ||
@@ -222,5 +223,5 @@ var o = { | ||
| f: function(a,b,c,d,e,f,g, cb) { | ||
| cb(null, [a,b,c,d,e,f,g, this.value]); | ||
| } | ||
| f: function(a, b, c, d, e, f, g, cb) { | ||
| cb(null, [a, b, c, d, e, f, g, this.value]); | ||
| }, | ||
@@ -231,7 +232,7 @@ }; | ||
| specify("receiver should still work", function() { | ||
| return prom(1,2,3,4,5,6,7).then(function(val){ | ||
| specify('receiver should still work', function() { | ||
| return prom(1, 2, 3, 4, 5, 6, 7).then(function(val) { | ||
| assert.deepEqual( | ||
| val, | ||
| [1,2,3,4,5,6,7, 15] | ||
| [1, 2, 3, 4, 5, 6, 7, 15] | ||
| ); | ||
@@ -245,5 +246,5 @@ }); | ||
| // In prfun, we don't wrap primitive errors. | ||
| describe.skip("Primitive errors wrapping", function() { | ||
| specify("when the node function throws it", function() { | ||
| return throwsStrings().then(assert.fail, function(e){ | ||
| describe.skip('Primitive errors wrapping', function() { | ||
| specify('when the node function throws it', function() { | ||
| return throwsStrings().then(assert.fail, function(e) { | ||
| assert(e instanceof Error); | ||
@@ -254,3 +255,3 @@ assert(e.message == tprimitive); | ||
| specify("when the node function throws it inside then", function() { | ||
| specify('when the node function throws it inside then', function() { | ||
| return Promise.resolve().then(function() { | ||
@@ -265,4 +266,4 @@ return throwsStrings().then(assert.fail, function(e) { | ||
| specify("when the node function errbacks it synchronously", function() { | ||
| return errbacksStrings().then(assert.fail, function(e){ | ||
| specify('when the node function errbacks it synchronously', function() { | ||
| return errbacksStrings().then(assert.fail, function(e) { | ||
| assert(e instanceof Error); | ||
@@ -273,5 +274,5 @@ assert(e.message == tprimitive); | ||
| specify("when the node function errbacks it synchronously inside then", function() { | ||
| return Promise.resolve().then(function(){ | ||
| errbacksStrings().then(assert.fail, function(e){ | ||
| specify('when the node function errbacks it synchronously inside then', function() { | ||
| return Promise.resolve().then(function() { | ||
| errbacksStrings().then(assert.fail, function(e) { | ||
| assert(e instanceof Error); | ||
@@ -283,4 +284,4 @@ assert(e.message == tprimitive); | ||
| specify("when the node function errbacks it asynchronously", function() { | ||
| return errbacksStringsAsync().then(assert.fail, function(e){ | ||
| specify('when the node function errbacks it asynchronously', function() { | ||
| return errbacksStringsAsync().then(assert.fail, function(e) { | ||
| assert(e instanceof Error); | ||
@@ -291,5 +292,5 @@ assert(e.message == tprimitive); | ||
| specify("when the node function errbacks it asynchronously inside then", function() { | ||
| return Promise.resolve().then(function(){ | ||
| errbacksStringsAsync().then(assert.fail, function(e){ | ||
| specify('when the node function errbacks it asynchronously inside then', function() { | ||
| return Promise.resolve().then(function() { | ||
| errbacksStringsAsync().then(assert.fail, function(e) { | ||
| assert(e instanceof Error); | ||
@@ -304,5 +305,5 @@ assert(e.message == tprimitive); | ||
| // Also, we don't support Promise#error() | ||
| describe.skip("RejectionError wrapping", function() { | ||
| describe.skip('RejectionError wrapping', function() { | ||
| var CustomError = function(){ }; | ||
| var CustomError = function() { }; | ||
@@ -312,22 +313,22 @@ CustomError.prototype = new Error(); | ||
| function isUntypedError( obj ) { | ||
| function isUntypedError(obj) { | ||
| return obj instanceof Error && | ||
| Object.getPrototypeOf( obj ) === Error.prototype; | ||
| Object.getPrototypeOf(obj) === Error.prototype; | ||
| } | ||
| if(!isUntypedError(new Error())) { | ||
| console.log("error must be untyped"); | ||
| if (!isUntypedError(new Error())) { | ||
| console.log('error must be untyped'); | ||
| } | ||
| if(isUntypedError(new CustomError())) { | ||
| console.log("customerror must be typed"); | ||
| if (isUntypedError(new CustomError())) { | ||
| console.log('customerror must be typed'); | ||
| } | ||
| var stringback = function(cb) { | ||
| cb("Primitive as error"); | ||
| cb('Primitive as error'); | ||
| }; | ||
| var errback = function(cb) { | ||
| cb(new Error("error as error")); | ||
| cb(new Error('error as error')); | ||
| }; | ||
@@ -340,7 +341,7 @@ | ||
| var stringthrow = function(cb) { | ||
| throw("Primitive as error"); | ||
| throw('Primitive as error'); | ||
| }; | ||
| var errthrow = function(cb) { | ||
| throw(new Error("error as error")); | ||
| throw(new Error('error as error')); | ||
| }; | ||
@@ -359,3 +360,3 @@ | ||
| specify("should wrap stringback", function(done) { | ||
| specify('should wrap stringback', function(done) { | ||
| stringback().error(function(e) { | ||
@@ -367,3 +368,3 @@ assert(e instanceof RejectionError); | ||
| specify("should wrap errback", function(done) { | ||
| specify('should wrap errback', function(done) { | ||
| errback().error(function(e) { | ||
@@ -375,4 +376,4 @@ assert(e instanceof RejectionError); | ||
| specify("should not wrap typeback", function(done) { | ||
| typeback().caught(CustomError, function(e){ | ||
| specify('should not wrap typeback', function(done) { | ||
| typeback().caught(CustomError, function(e) { | ||
| done(); | ||
@@ -382,4 +383,4 @@ }); | ||
| specify("should not wrap stringthrow", function(done) { | ||
| stringthrow().error(assert.fail).caught(function(e){ | ||
| specify('should not wrap stringthrow', function(done) { | ||
| stringthrow().error(assert.fail).caught(function(e) { | ||
| assert(e instanceof Error); | ||
@@ -390,3 +391,3 @@ done(); | ||
| specify("should not wrap errthrow", function(done) { | ||
| specify('should not wrap errthrow', function(done) { | ||
| errthrow().error(assert.fail).caught(function(e) { | ||
@@ -398,5 +399,5 @@ assert(e instanceof Error); | ||
| specify("should not wrap typethrow", function(done) { | ||
| specify('should not wrap typethrow', function(done) { | ||
| typethrow().error(assert.fail) | ||
| .caught(CustomError, function(e){ | ||
| .caught(CustomError, function(e) { | ||
| done(); | ||
@@ -403,0 +404,0 @@ }); |
+69
-67
@@ -1,5 +0,5 @@ | ||
| "use strict"; | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -10,5 +10,5 @@ var fulfilled = Promise.resolve.bind(Promise); | ||
| describe("Promise.props", function () { | ||
| describe('Promise.props', function() { | ||
| specify("should reject undefined", function() { | ||
| specify('should reject undefined', function() { | ||
| return Promise.props().then(assert.fail, function(e) { | ||
@@ -19,4 +19,4 @@ assert(e instanceof TypeError); | ||
| specify("should reject primitive", function() { | ||
| return Promise.props("str").then(assert.fail, function(e) { | ||
| specify('should reject primitive', function() { | ||
| return Promise.props('str').then(assert.fail, function(e) { | ||
| assert(e instanceof TypeError); | ||
@@ -26,6 +26,6 @@ }); | ||
| specify("should resolve to new object", function() { | ||
| specify('should resolve to new object', function() { | ||
| var o = {}; | ||
| return Promise.props(o).then(function(v){ | ||
| assert( v !== o ); | ||
| return Promise.props(o).then(function(v) { | ||
| assert(v !== o); | ||
| assert.deepEqual(o, v); | ||
@@ -35,13 +35,13 @@ }); | ||
| specify("should resolve value properties", function() { | ||
| specify('should resolve value properties', function() { | ||
| var o = { | ||
| one: 1, | ||
| two: 2, | ||
| three: 3 | ||
| three: 3, | ||
| }; | ||
| return Promise.props(o).then(function(v){ | ||
| return Promise.props(o).then(function(v) { | ||
| assert.deepEqual({ | ||
| one: 1, | ||
| two: 2, | ||
| three: 3 | ||
| three: 3, | ||
| }, v); | ||
@@ -51,13 +51,13 @@ }); | ||
| specify("should resolve immediate properties", function() { | ||
| specify('should resolve immediate properties', function() { | ||
| var o = { | ||
| one: fulfilled(1), | ||
| two: fulfilled(2), | ||
| three: fulfilled(3) | ||
| three: fulfilled(3), | ||
| }; | ||
| return Promise.props(o).then(function(v){ | ||
| return Promise.props(o).then(function(v) { | ||
| assert.deepEqual({ | ||
| one: 1, | ||
| two: 2, | ||
| three: 3 | ||
| three: 3, | ||
| }, v); | ||
@@ -67,12 +67,12 @@ }); | ||
| specify("should resolve eventual properties", function() { | ||
| var d1 = pending(), | ||
| d2 = pending(), | ||
| d3 = pending(); | ||
| specify('should resolve eventual properties', function() { | ||
| var d1 = pending(); | ||
| var d2 = pending(); | ||
| var d3 = pending(); | ||
| var o = { | ||
| one: d1.promise, | ||
| two: d2.promise, | ||
| three: d3.promise | ||
| three: d3.promise, | ||
| }; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -82,7 +82,7 @@ d2.resolve(2); | ||
| }, 13); | ||
| return Promise.props(o).then(function(v){ | ||
| return Promise.props(o).then(function(v) { | ||
| assert.deepEqual({ | ||
| one: 1, | ||
| two: 2, | ||
| three: 3 | ||
| three: 3, | ||
| }, v); | ||
@@ -92,28 +92,28 @@ }); | ||
| specify("should reject if any input promise rejects", function() { | ||
| specify('should reject if any input promise rejects', function() { | ||
| var o = { | ||
| one: fulfilled(1), | ||
| two: rejected(2), | ||
| three: fulfilled(3) | ||
| three: fulfilled(3), | ||
| }; | ||
| return Promise.props(o).then(assert.fail, function(v) { | ||
| assert( v === 2 ); | ||
| assert(v === 2); | ||
| }); | ||
| }); | ||
| specify("should accept a promise for an object", function() { | ||
| specify('should accept a promise for an object', function() { | ||
| var o = { | ||
| one: fulfilled(1), | ||
| two: fulfilled(2), | ||
| three: fulfilled(3) | ||
| three: fulfilled(3), | ||
| }; | ||
| var d1 = pending(); | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(o); | ||
| }, 13); | ||
| return Promise.props(d1.promise).then(function(v){ | ||
| return Promise.props(d1.promise).then(function(v) { | ||
| assert.deepEqual({ | ||
| one: 1, | ||
| two: 2, | ||
| three: 3 | ||
| three: 3, | ||
| }, v); | ||
@@ -123,6 +123,6 @@ }); | ||
| specify("should reject a promise for a primitive", function() { | ||
| specify('should reject a promise for a primitive', function() { | ||
| var d1 = pending(); | ||
| setTimeout(function(){ | ||
| d1.resolve("text"); | ||
| setTimeout(function() { | ||
| d1.resolve('text'); | ||
| }, 13); | ||
@@ -134,16 +134,16 @@ return Promise.props(d1.promise).then(assert.fail, function(e) { | ||
| specify("should accept thenables in properties", function() { | ||
| var t1 = {then: function(cb){cb(1);}}; | ||
| var t2 = {then: function(cb){cb(2);}}; | ||
| var t3 = {then: function(cb){cb(3);}}; | ||
| specify('should accept thenables in properties', function() { | ||
| var t1 = {then: function(cb) {cb(1);}}; | ||
| var t2 = {then: function(cb) {cb(2);}}; | ||
| var t3 = {then: function(cb) {cb(3);}}; | ||
| var o = { | ||
| one: t1, | ||
| two: t2, | ||
| three: t3 | ||
| three: t3, | ||
| }; | ||
| return Promise.props(o).then(function(v){ | ||
| return Promise.props(o).then(function(v) { | ||
| assert.deepEqual({ | ||
| one: 1, | ||
| two: 2, | ||
| three: 3 | ||
| three: 3, | ||
| }, v); | ||
@@ -153,29 +153,29 @@ }); | ||
| specify("should accept a thenable for thenables in properties", function() { | ||
| specify('should accept a thenable for thenables in properties', function() { | ||
| var o = { | ||
| then: function (f) { | ||
| then: function(f) { | ||
| f({ | ||
| one: { | ||
| then: function (cb) { | ||
| then: function(cb) { | ||
| cb(1); | ||
| } | ||
| }, | ||
| }, | ||
| two: { | ||
| then: function (cb) { | ||
| then: function(cb) { | ||
| cb(2); | ||
| } | ||
| }, | ||
| }, | ||
| three: { | ||
| then: function (cb) { | ||
| then: function(cb) { | ||
| cb(3); | ||
| } | ||
| } | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
| }, | ||
| }; | ||
| return Promise.props(o).then(function(v){ | ||
| return Promise.props(o).then(function(v) { | ||
| assert.deepEqual({ | ||
| one: 1, | ||
| two: 2, | ||
| three: 3 | ||
| three: 3, | ||
| }, v); | ||
@@ -185,4 +185,5 @@ }); | ||
| // jscs: disable requireCapitalizedComments | ||
| /* | ||
| specify("sends { key, value } progress updates", function(done) { | ||
| specify('sends { key, value } progress updates', function(done) { | ||
| var deferred1 = Q.defer(); | ||
@@ -194,10 +195,10 @@ var deferred2 = Q.defer(); | ||
| Q.delay(50).then(function () { | ||
| deferred1.notify("a"); | ||
| deferred1.notify('a'); | ||
| }); | ||
| Q.delay(100).then(function () { | ||
| deferred2.notify("b"); | ||
| deferred2.notify('b'); | ||
| deferred2.resolve(); | ||
| }); | ||
| Q.delay(150).then(function () { | ||
| deferred1.notify("c"); | ||
| deferred1.notify('c'); | ||
| deferred1.resolve(); | ||
@@ -211,5 +212,5 @@ }); | ||
| assert.deepEqual(progressValues, [ | ||
| { key: "one", value: "a" }, | ||
| { key: "two", value: "b" }, | ||
| { key: "one", value: "c" } | ||
| { key: 'one', value: 'a' }, | ||
| { key: 'two', value: 'b' }, | ||
| { key: 'one', value: 'c' } | ||
| ]); | ||
@@ -224,11 +225,12 @@ done(); | ||
| */ | ||
| // jscs: enable requireCapitalizedComments | ||
| specify("treats arrays for their properties", function() { | ||
| var o = [1,2,3]; | ||
| specify('treats arrays for their properties', function() { | ||
| var o = [1, 2, 3]; | ||
| return Promise.props(o).then(function(v){ | ||
| return Promise.props(o).then(function(v) { | ||
| assert.deepEqual({ | ||
| 0: 1, | ||
| 1: 2, | ||
| 2: 3 | ||
| 2: 3, | ||
| }, v); | ||
@@ -235,0 +237,0 @@ }); |
+92
-91
@@ -1,5 +0,6 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -28,10 +29,10 @@ /*! | ||
| describe("Promise#finally", function () { | ||
| describe('Promise#finally', function() { | ||
| var exception1 = new Error("boo!"); | ||
| var exception2 = new TypeError("evil!"); | ||
| var exception1 = new Error('boo!'); | ||
| var exception2 = new TypeError('evil!'); | ||
| describe("when nothing is passed", function() { | ||
| it("should do nothing", function() { | ||
| return Promise.resolve("foo") | ||
| describe('when nothing is passed', function() { | ||
| it('should do nothing', function() { | ||
| return Promise.resolve('foo') | ||
| ['finally']() | ||
@@ -41,4 +42,4 @@ ['finally']() | ||
| ['finally']() | ||
| .then(function(val){ | ||
| assert(val === "foo"); | ||
| .then(function(val) { | ||
| assert(val === 'foo'); | ||
| }); | ||
@@ -48,30 +49,30 @@ }); | ||
| describe("when the promise is fulfilled", function () { | ||
| describe('when the promise is fulfilled', function() { | ||
| it("should call the callback", function () { | ||
| it('should call the callback', function() { | ||
| var called = false; | ||
| return Promise.resolve("foo") | ||
| ['finally'](function () { | ||
| return Promise.resolve('foo') | ||
| ['finally'](function() { | ||
| called = true; | ||
| }) | ||
| .then(function () { | ||
| assert.equal(called,true); | ||
| .then(function() { | ||
| assert.equal(called, true); | ||
| }); | ||
| }); | ||
| it("should fulfill with the original value", function () { | ||
| return Promise.resolve("foo") | ||
| ['finally'](function () { | ||
| return "bar"; | ||
| it('should fulfill with the original value', function() { | ||
| return Promise.resolve('foo') | ||
| ['finally'](function() { | ||
| return 'bar'; | ||
| }) | ||
| .then(function (result) { | ||
| assert.equal(result,"foo"); | ||
| .then(function(result) { | ||
| assert.equal(result, 'foo'); | ||
| }); | ||
| }); | ||
| describe("when the callback returns a promise", function () { | ||
| describe('when the callback returns a promise', function() { | ||
| describe("that is fulfilled", function () { | ||
| it("should fulfill with the original reason after that promise resolves", function () { | ||
| describe('that is fulfilled', function() { | ||
| it('should fulfill with the original reason after that promise resolves', function() { | ||
| var pending = true; | ||
@@ -82,9 +83,9 @@ var promise = Promise.delay(null, 25).then(function() { | ||
| return Promise.resolve("foo") | ||
| ['finally'](function () { | ||
| return Promise.resolve('foo') | ||
| ['finally'](function() { | ||
| return promise; | ||
| }) | ||
| .then(function (result) { | ||
| .then(function(result) { | ||
| assert.equal(pending, false); | ||
| assert.equal(result, "foo"); | ||
| assert.equal(result, 'foo'); | ||
| }); | ||
@@ -94,12 +95,12 @@ }); | ||
| describe("that is rejected", function () { | ||
| it("should reject with this new rejection reason", function () { | ||
| return Promise.resolve("foo") | ||
| ['finally'](function () { | ||
| describe('that is rejected', function() { | ||
| it('should reject with this new rejection reason', function() { | ||
| return Promise.resolve('foo') | ||
| ['finally'](function() { | ||
| return Promise.reject(exception1); | ||
| }) | ||
| .then(function () { | ||
| .then(function() { | ||
| assert.fail(); | ||
| }, function (exception) { | ||
| assert.equal(exception,exception1); | ||
| }, function(exception) { | ||
| assert.equal(exception, exception1); | ||
| }); | ||
@@ -111,12 +112,12 @@ }); | ||
| describe("when the callback throws an exception", function () { | ||
| it("should reject with this new exception", function () { | ||
| return Promise.resolve("foo") | ||
| ['finally'](function () { | ||
| describe('when the callback throws an exception', function() { | ||
| it('should reject with this new exception', function() { | ||
| return Promise.resolve('foo') | ||
| ['finally'](function() { | ||
| throw exception1; | ||
| }) | ||
| .then(function () { | ||
| .then(function() { | ||
| assert.fail(); | ||
| }, function (exception) { | ||
| assert.equal(exception,exception1); | ||
| }, function(exception) { | ||
| assert.equal(exception, exception1); | ||
| }); | ||
@@ -128,34 +129,34 @@ }); | ||
| describe("when the promise is rejected", function () { | ||
| describe('when the promise is rejected', function() { | ||
| it("should call the callback", function () { | ||
| it('should call the callback', function() { | ||
| var called = false; | ||
| return Promise.reject(exception1) | ||
| ['finally'](function () { | ||
| ['finally'](function() { | ||
| called = true; | ||
| }) | ||
| .then(function () { | ||
| .then(function() { | ||
| assert.fail(); | ||
| }, function () { | ||
| assert.equal(called,true); | ||
| }, function() { | ||
| assert.equal(called, true); | ||
| }); | ||
| }); | ||
| it("should reject with the original reason", function () { | ||
| it('should reject with the original reason', function() { | ||
| return Promise.reject(exception1) | ||
| ['finally'](function () { | ||
| return "bar"; | ||
| ['finally'](function() { | ||
| return 'bar'; | ||
| }) | ||
| .then(function () { | ||
| .then(function() { | ||
| assert.fail(); | ||
| }, function (exception) { | ||
| assert.equal(exception,exception1); | ||
| }, function(exception) { | ||
| assert.equal(exception, exception1); | ||
| }); | ||
| }); | ||
| describe("when the callback returns a promise", function () { | ||
| describe('when the callback returns a promise', function() { | ||
| describe("that is fulfilled", function () { | ||
| it("should reject with the original reason after that promise resolves", function () { | ||
| describe('that is fulfilled', function() { | ||
| it('should reject with the original reason after that promise resolves', function() { | ||
| var pending = true; | ||
@@ -167,7 +168,7 @@ var promise = Promise.delay(null, 25).then(function() { | ||
| return Promise.reject(exception1) | ||
| ['finally'](function () { | ||
| ['finally'](function() { | ||
| return promise; | ||
| }).then(function () { | ||
| }).then(function() { | ||
| assert.fail(); | ||
| }, function (exception) { | ||
| }, function(exception) { | ||
| assert.equal(pending, false); | ||
@@ -179,11 +180,11 @@ assert.equal(exception, exception1); | ||
| describe("that is rejected", function () { | ||
| it("should reject with the new reason", function () { | ||
| describe('that is rejected', function() { | ||
| it('should reject with the new reason', function() { | ||
| return Promise.reject(exception1) | ||
| ['finally'](function () { | ||
| ['finally'](function() { | ||
| return Promise.reject(exception2); | ||
| }).then(function () { | ||
| }).then(function() { | ||
| assert.fail(); | ||
| }, function (exception) { | ||
| assert.equal(exception,exception2); | ||
| }, function(exception) { | ||
| assert.equal(exception, exception2); | ||
| }); | ||
@@ -194,12 +195,12 @@ }); | ||
| describe("when the callback throws an exception", function () { | ||
| it("should reject with this new exception", function () { | ||
| describe('when the callback throws an exception', function() { | ||
| it('should reject with this new exception', function() { | ||
| return Promise.reject(exception1) | ||
| ['finally'](function () { | ||
| ['finally'](function() { | ||
| throw exception2; | ||
| }) | ||
| .then(function () { | ||
| .then(function() { | ||
| assert.fail(); | ||
| }, function (exception) { | ||
| assert.equal(exception,exception2); | ||
| }, function(exception) { | ||
| assert.equal(exception, exception2); | ||
| }); | ||
@@ -210,22 +211,22 @@ }); | ||
| describe("when the callback returns a thenable", function () { | ||
| describe('when the callback returns a thenable', function() { | ||
| describe("that will fulfill", function () { | ||
| it("should reject with the original reason after that", function () { | ||
| describe('that will fulfill', function() { | ||
| it('should reject with the original reason after that', function() { | ||
| var promise = { | ||
| then: function(fn) { | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| fn(15); | ||
| }, 13); | ||
| } | ||
| }, | ||
| }; | ||
| return Promise.reject(exception1) | ||
| ['finally'](function () { | ||
| ['finally'](function() { | ||
| return promise; | ||
| }) | ||
| .then(function () { | ||
| .then(function() { | ||
| assert.fail(); | ||
| }, function (exception) { | ||
| assert.equal(exception,exception1); | ||
| }, function(exception) { | ||
| assert.equal(exception, exception1); | ||
| }); | ||
@@ -235,20 +236,20 @@ }); | ||
| describe("that is rejected", function () { | ||
| it("should reject with the new reason", function () { | ||
| describe('that is rejected', function() { | ||
| it('should reject with the new reason', function() { | ||
| var promise = { | ||
| then: function(f, fn) { | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| fn(exception2); | ||
| }, 13); | ||
| } | ||
| }, | ||
| }; | ||
| return Promise.reject(exception1) | ||
| ['finally'](function () { | ||
| ['finally'](function() { | ||
| return promise; | ||
| }) | ||
| .then(function () { | ||
| .then(function() { | ||
| assert.fail(); | ||
| }, function (exception) { | ||
| assert.equal(exception,exception2); | ||
| }, function(exception) { | ||
| assert.equal(exception, exception2); | ||
| }); | ||
@@ -255,0 +256,0 @@ }); |
+25
-24
@@ -1,5 +0,6 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -27,4 +28,4 @@ /* | ||
| describe("Promise#nodify", function () { | ||
| var mkspy= function(calls) { | ||
| describe('Promise#nodify', function() { | ||
| var mkspy = function(calls) { | ||
| return function spy() { | ||
@@ -37,3 +38,3 @@ var args = Array.prototype.slice.call(arguments); | ||
| it("calls back with a resolution", function () { | ||
| it('calls back with a resolution', function() { | ||
| var calls = []; | ||
@@ -49,3 +50,3 @@ var spy = mkspy(calls); | ||
| it("calls back with an error", function () { | ||
| it('calls back with an error', function() { | ||
| var calls = []; | ||
@@ -61,4 +62,4 @@ var spy = mkspy(calls); | ||
| it("forwards a promise", function () { | ||
| return Promise.resolve(10).nodify().then(function (ten) { | ||
| it('forwards a promise', function() { | ||
| return Promise.resolve(10).nodify().then(function(ten) { | ||
| assert.deepEqual(ten, 10); | ||
@@ -71,10 +72,10 @@ }); | ||
| //Should be the last test because it is ridiculously hard to test | ||
| //if something throws in the node process | ||
| // Should be the last test because it is ridiculously hard to test | ||
| // if something throws in the node process | ||
| var isNodeJS = typeof process !== "undefined" && | ||
| typeof process.execPath === "string"; | ||
| var isNodeJS = typeof process !== 'undefined' && | ||
| typeof process.execPath === 'string'; | ||
| if( isNodeJS ) { | ||
| describe("nodify", function () { | ||
| if (isNodeJS) { | ||
| describe('nodify', function() { | ||
@@ -87,3 +88,3 @@ var h = []; | ||
| originalException = process.listeners('uncaughtException').pop(); | ||
| if (!originalException) break; | ||
| if (!originalException) { break; } | ||
| process.removeListener('uncaughtException', originalException); | ||
@@ -96,5 +97,5 @@ h.push(originalException); | ||
| var originalException; | ||
| while(true) { | ||
| while (true) { | ||
| originalException = process.listeners('uncaughtException').pop(); | ||
| if (!originalException) break; | ||
| if (!originalException) { break; } | ||
| process.removeListener('uncaughtException', originalException); | ||
@@ -105,3 +106,3 @@ } | ||
| function addHandlersBack() { | ||
| for( var i = 0, len = h.length; i < len; ++i ) { | ||
| for (var i = 0, len = h.length; i < len; ++i) { | ||
| process.addListener('uncaughtException', h[i]); | ||
@@ -115,14 +116,14 @@ } | ||
| it("throws normally in the node process if the function throws", function (done) { | ||
| it('throws normally in the node process if the function throws', function(done) { | ||
| clearHandlers(); | ||
| var promise = Promise.resolve(10); | ||
| var turns = 0; | ||
| process.nextTick(function(){ | ||
| process.nextTick(function() { | ||
| turns++; | ||
| }); | ||
| promise.nodify(thrower); | ||
| process.addListener("uncaughtException", function(err) { | ||
| process.addListener('uncaughtException', function(err) { | ||
| clearHandlersNoRestore(); | ||
| assert( err === e ); | ||
| assert( turns === 1); | ||
| assert(err === e); | ||
| assert(turns === 1); | ||
| done(); | ||
@@ -129,0 +130,0 @@ }); |
+38
-35
@@ -1,5 +0,6 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -10,5 +11,5 @@ var fulfilled = Promise.resolve.bind(Promise); | ||
| describe("Promise.race", function(){ | ||
| describe('Promise.race', function() { | ||
| it("remains forever pending when passed an empty array", function (done) { | ||
| it('remains forever pending when passed an empty array', function(done) { | ||
| var p = Promise.race([]); | ||
@@ -29,3 +30,3 @@ var pending = true; | ||
| it("remains forever pending when passed a promise of an empty array", function (done) { | ||
| it('remains forever pending when passed a promise of an empty array', function(done) { | ||
| var p = fulfilled([]).race(); | ||
@@ -46,4 +47,4 @@ var pending = true; | ||
| it("fulfills when passed an immediate value", function () { | ||
| return Promise.race([1,2,3]).then(function(v){ | ||
| it('fulfills when passed an immediate value', function() { | ||
| return Promise.race([1, 2, 3]).then(function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -53,4 +54,4 @@ }); | ||
| it("fulfills when passed a promise of an immediate value", function () { | ||
| return fulfilled([1,2,3]).race().then(function(v){ | ||
| it('fulfills when passed a promise of an immediate value', function() { | ||
| return fulfilled([1, 2, 3]).race().then(function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -60,3 +61,3 @@ }); | ||
| it("fulfills when passed an immediately fulfilled value", function () { | ||
| it('fulfills when passed an immediately fulfilled value', function() { | ||
| var d1 = pending(); | ||
@@ -74,3 +75,3 @@ d1.resolve(1); | ||
| return Promise.race([p1, p2, p3]).then(function(v){ | ||
| return Promise.race([p1, p2, p3]).then(function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -80,3 +81,3 @@ }); | ||
| it("fulfills when passed a promise of an immediately fulfilled value", function () { | ||
| it('fulfills when passed a promise of an immediately fulfilled value', function() { | ||
| var d1 = pending(); | ||
@@ -94,3 +95,3 @@ d1.resolve(1); | ||
| return fulfilled([p1, p2, p3]).race().then(function(v){ | ||
| return fulfilled([p1, p2, p3]).race().then(function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -100,3 +101,3 @@ }); | ||
| it("fulfills when passed an eventually fulfilled value", function () { | ||
| it('fulfills when passed an eventually fulfilled value', function() { | ||
| var d1 = pending(); | ||
@@ -111,3 +112,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -118,3 +119,3 @@ d2.resolve(2); | ||
| return Promise.race([p1, p2, p3]).then(function(v){ | ||
| return Promise.race([p1, p2, p3]).then(function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -124,3 +125,3 @@ }); | ||
| it("fulfills when passed a promise of an eventually fulfilled value", function () { | ||
| it('fulfills when passed a promise of an eventually fulfilled value', function() { | ||
| var d1 = pending(); | ||
@@ -135,3 +136,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.resolve(1); | ||
@@ -142,3 +143,3 @@ d2.resolve(2); | ||
| return fulfilled([p1, p2, p3]).race().then(function(v){ | ||
| return fulfilled([p1, p2, p3]).race().then(function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -148,4 +149,4 @@ }); | ||
| it("rejects when passed an immediate value", function () { | ||
| return Promise.race([rejected(1), 2, 3]).then(assert.fail, function(v){ | ||
| it('rejects when passed an immediate value', function() { | ||
| return Promise.race([rejected(1), 2, 3]).then(assert.fail, function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -155,4 +156,4 @@ }); | ||
| it("rejects when passed a promise of an immediate value", function () { | ||
| return fulfilled([rejected(1), 2, 3]).race().then(assert.fail, function(v){ | ||
| it('rejects when passed a promise of an immediate value', function() { | ||
| return fulfilled([rejected(1), 2, 3]).race().then(assert.fail, function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -162,3 +163,3 @@ }); | ||
| it("rejects when passed an immediately rejected value", function () { | ||
| it('rejects when passed an immediately rejected value', function() { | ||
| var d1 = pending(); | ||
@@ -176,3 +177,4 @@ d1.reject(1); | ||
| return Promise.race([p1, p2, , , p3]).then(assert.fail, function(v){ | ||
| /* jshint elision: true */ | ||
| return Promise.race([p1, p2, , , p3]).then(assert.fail, function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -182,3 +184,3 @@ }); | ||
| it("rejects when passed a promise of an immediately rejected value", function () { | ||
| it('rejects when passed a promise of an immediately rejected value', function() { | ||
| var d1 = pending(); | ||
@@ -196,3 +198,4 @@ d1.reject(1); | ||
| return fulfilled([p1, p2, , , p3]).race().then(assert.fail, function(v){ | ||
| /* jshint elision: true */ | ||
| return fulfilled([p1, p2, , , p3]).race().then(assert.fail, function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -202,3 +205,3 @@ }); | ||
| it("rejects when passed an eventually rejected value", function () { | ||
| it('rejects when passed an eventually rejected value', function() { | ||
| var d1 = pending(); | ||
@@ -213,3 +216,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.reject(1); | ||
@@ -220,3 +223,3 @@ d2.resolve(2); | ||
| return Promise.race([p1, p2, p3]).then(assert.fail, function(v){ | ||
| return Promise.race([p1, p2, p3]).then(assert.fail, function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -226,3 +229,3 @@ }); | ||
| it("rejects when passed a promise of an eventually rejected value", function () { | ||
| it('rejects when passed a promise of an eventually rejected value', function() { | ||
| var d1 = pending(); | ||
@@ -237,3 +240,3 @@ var p1 = d1.promise; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d1.reject(1); | ||
@@ -244,3 +247,3 @@ d2.resolve(2); | ||
| return fulfilled([p1, p2, p3]).race().then(assert.fail, function(v){ | ||
| return fulfilled([p1, p2, p3]).race().then(assert.fail, function(v) { | ||
| assert.deepEqual(v, 1); | ||
@@ -250,3 +253,3 @@ }); | ||
| it("rejects when passed a rejected promise", function() { | ||
| it('rejects when passed a rejected promise', function() { | ||
| return rejected([]).race().then(assert.fail, function(v) { | ||
@@ -253,0 +256,0 @@ assert.deepEqual(v, []); |
+88
-88
@@ -1,5 +0,5 @@ | ||
| "use strict"; | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -10,118 +10,118 @@ var fulfilled = Promise.resolve.bind(Promise); | ||
| function promised(val) { | ||
| return Promise.delay(val, 4); | ||
| return Promise.delay(val, 4); | ||
| } | ||
| function thenabled(val) { | ||
| return { | ||
| then: function(f){ | ||
| setTimeout(function() { | ||
| f(val); | ||
| }, 4); | ||
| } | ||
| }; | ||
| return { | ||
| then: function(f) { | ||
| setTimeout(function() { | ||
| f(val); | ||
| }, 4); | ||
| }, | ||
| }; | ||
| } | ||
| describe("Promise.prototype.reduce", function() { | ||
| describe('Promise.prototype.reduce', function() { | ||
| it("should allow returning values", function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| it('should allow returning values', function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| return Promise.reduce(a, function(total, a) { | ||
| return total + a + 5; | ||
| }, 0).then(function(total){ | ||
| assert.equal(total, 1+5 + 2+5 + 3+5); | ||
| }); | ||
| return Promise.reduce(a, function(total, a) { | ||
| return total + a + 5; | ||
| }, 0).then(function(total) { | ||
| assert.equal(total, 1 + 5 + 2 + 5 + 3 + 5); | ||
| }); | ||
| }); | ||
| it("should allow returning promises", function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| it('should allow returning promises', function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| return Promise.reduce(a, function(total, a) { | ||
| return promised(5).then(function(b) { | ||
| return total + a + b; | ||
| }); | ||
| }, 0).then(function(total){ | ||
| assert.equal(total, 1+5 + 2+5 + 3+5); | ||
| }); | ||
| return Promise.reduce(a, function(total, a) { | ||
| return promised(5).then(function(b) { | ||
| return total + a + b; | ||
| }); | ||
| }, 0).then(function(total) { | ||
| assert.equal(total, 1 + 5 + 2 + 5 + 3 + 5); | ||
| }); | ||
| }); | ||
| it("should allow returning thenables", function() { | ||
| var b = [1,2,3]; | ||
| var a = []; | ||
| it('should allow returning thenables', function() { | ||
| var b = [1, 2, 3]; | ||
| var a = []; | ||
| return Promise.reduce(b, function(total, cur) { | ||
| a.push(cur); | ||
| return thenabled(3); | ||
| }, 0).then(function(total){ | ||
| assert.equal(total, 3); | ||
| assert.deepEqual(a, b); | ||
| }); | ||
| return Promise.reduce(b, function(total, cur) { | ||
| a.push(cur); | ||
| return thenabled(3); | ||
| }, 0).then(function(total) { | ||
| assert.equal(total, 3); | ||
| assert.deepEqual(a, b); | ||
| }); | ||
| }); | ||
| it("propagates error", function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| var e = new Error("asd"); | ||
| return Promise.reduce(a, function(total, a) { | ||
| if (a > 2) { | ||
| throw e; | ||
| } | ||
| return total + a + 5; | ||
| }, 0).then(assert.fail, function(err) { | ||
| assert.equal(err, e); | ||
| }); | ||
| it('propagates error', function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| var e = new Error('asd'); | ||
| return Promise.reduce(a, function(total, a) { | ||
| if (a > 2) { | ||
| throw e; | ||
| } | ||
| return total + a + 5; | ||
| }, 0).then(assert.fail, function(err) { | ||
| assert.equal(err, e); | ||
| }); | ||
| }); | ||
| }); | ||
| describe("Promise.prototype.reduceRight", function() { | ||
| describe('Promise.prototype.reduceRight', function() { | ||
| it("should allow returning values", function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| it('should allow returning values', function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| return Promise.reduceRight(a, function(total, a) { | ||
| return total + a + 5; | ||
| }, 0).then(function(total){ | ||
| assert.equal(total, 1+5 + 2+5 + 3+5); | ||
| }); | ||
| return Promise.reduceRight(a, function(total, a) { | ||
| return total + a + 5; | ||
| }, 0).then(function(total) { | ||
| assert.equal(total, 1 + 5 + 2 + 5 + 3 + 5); | ||
| }); | ||
| }); | ||
| it("should allow returning promises", function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| it('should allow returning promises', function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| return Promise.reduceRight(a, function(total, a) { | ||
| return promised(5).then(function(b) { | ||
| return total + a + b; | ||
| }); | ||
| }, 0).then(function(total){ | ||
| assert.equal(total, 1+5 + 2+5 + 3+5); | ||
| }); | ||
| return Promise.reduceRight(a, function(total, a) { | ||
| return promised(5).then(function(b) { | ||
| return total + a + b; | ||
| }); | ||
| }, 0).then(function(total) { | ||
| assert.equal(total, 1 + 5 + 2 + 5 + 3 + 5); | ||
| }); | ||
| }); | ||
| it("should allow returning thenables", function() { | ||
| var b = [1,2,3]; | ||
| var a = []; | ||
| var br = [3,2,1]; | ||
| it('should allow returning thenables', function() { | ||
| var b = [1, 2, 3]; | ||
| var a = []; | ||
| var br = [3, 2, 1]; | ||
| return Promise.reduceRight(b, function(total, cur) { | ||
| a.push(cur); | ||
| return thenabled(3); | ||
| }, 0).then(function(total){ | ||
| assert.equal(total, 3); | ||
| assert.deepEqual(a, br); | ||
| }); | ||
| return Promise.reduceRight(b, function(total, cur) { | ||
| a.push(cur); | ||
| return thenabled(3); | ||
| }, 0).then(function(total) { | ||
| assert.equal(total, 3); | ||
| assert.deepEqual(a, br); | ||
| }); | ||
| }); | ||
| it("propagates error", function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| var e = new Error("asd"); | ||
| return Promise.reduceRight(a, function(total, a) { | ||
| if (a > 2) { | ||
| throw e; | ||
| } | ||
| return total + a + 5; | ||
| }, 0).then(assert.fail, function(err) { | ||
| assert.equal(err, e); | ||
| }); | ||
| it('propagates error', function() { | ||
| var a = [promised(1), promised(2), promised(3)]; | ||
| var e = new Error('asd'); | ||
| return Promise.reduceRight(a, function(total, a) { | ||
| if (a > 2) { | ||
| throw e; | ||
| } | ||
| return total + a + 5; | ||
| }, 0).then(assert.fail, function(err) { | ||
| assert.equal(err, e); | ||
| }); | ||
| }); | ||
| }); |
+54
-53
@@ -1,5 +0,6 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -10,61 +11,61 @@ var fulfilled = Promise.resolve.bind(Promise); | ||
| describe("tap", function () { | ||
| specify("passes through value", function(done) { | ||
| Promise.resolve("test").tap(function() { | ||
| return 3; | ||
| }).then(function(value){ | ||
| assert.equal(value, "test"); | ||
| done(); | ||
| }); | ||
| describe('tap', function() { | ||
| specify('passes through value', function(done) { | ||
| Promise.resolve('test').tap(function() { | ||
| return 3; | ||
| }).then(function(value) { | ||
| assert.equal(value, 'test'); | ||
| done(); | ||
| }); | ||
| }); | ||
| specify("passes through value after returned promise is fulfilled", function(done) { | ||
| var async = false; | ||
| Promise.resolve("test").tap(function() { | ||
| return new Promise(function(r) { | ||
| setTimeout(function(){ | ||
| async = true; | ||
| r(3); | ||
| }, 13); | ||
| }); | ||
| }).then(function(value){ | ||
| assert(async); | ||
| assert.equal(value, "test"); | ||
| done(); | ||
| }); | ||
| specify('passes through value after returned promise is fulfilled', function(done) { | ||
| var async = false; | ||
| Promise.resolve('test').tap(function() { | ||
| return new Promise(function(r) { | ||
| setTimeout(function() { | ||
| async = true; | ||
| r(3); | ||
| }, 13); | ||
| }); | ||
| }).then(function(value) { | ||
| assert(async); | ||
| assert.equal(value, 'test'); | ||
| done(); | ||
| }); | ||
| }); | ||
| specify("is not called on rejected promise", function(done) { | ||
| var called = false; | ||
| Promise.reject("test").tap(function() { | ||
| called = true; | ||
| }).caught(function(value){ | ||
| assert(!called); | ||
| done(); | ||
| }); | ||
| specify('is not called on rejected promise', function(done) { | ||
| var called = false; | ||
| Promise.reject('test').tap(function() { | ||
| called = true; | ||
| }).caught(function(value) { | ||
| assert(!called); | ||
| done(); | ||
| }); | ||
| }); | ||
| specify("passes immediate rejection", function(done) { | ||
| var err = new Error(); | ||
| Promise.resolve("test").tap(function() { | ||
| throw err; | ||
| }).tap(assert.fail).caught(function(e){ | ||
| assert(err === e); | ||
| done(); | ||
| }); | ||
| specify('passes immediate rejection', function(done) { | ||
| var err = new Error(); | ||
| Promise.resolve('test').tap(function() { | ||
| throw err; | ||
| }).tap(assert.fail).caught(function(e) { | ||
| assert(err === e); | ||
| done(); | ||
| }); | ||
| }); | ||
| specify("passes eventual rejection", function(done) { | ||
| var err = new Error(); | ||
| Promise.resolve("test").tap(function() { | ||
| return new Promise(function(_, rej) { | ||
| setTimeout(function(){ | ||
| rej(err); | ||
| }, 13); | ||
| }); | ||
| }).tap(assert.fail).caught(function(e) { | ||
| assert(err === e); | ||
| done(); | ||
| }); | ||
| specify('passes eventual rejection', function(done) { | ||
| var err = new Error(); | ||
| Promise.resolve('test').tap(function() { | ||
| return new Promise(function(_, rej) { | ||
| setTimeout(function() { | ||
| rej(err); | ||
| }, 13); | ||
| }); | ||
| }).tap(assert.fail).caught(function(e) { | ||
| assert(err === e); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); |
+35
-33
@@ -1,5 +0,6 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -27,15 +28,15 @@ /* | ||
| describe("timeout", function () { | ||
| it("should do nothing if the promise fulfills quickly", function () { | ||
| describe('timeout', function() { | ||
| it('should do nothing if the promise fulfills quickly', function() { | ||
| return Promise.delay(10).timeout(200); | ||
| }); | ||
| it("should do nothing if the promise rejects quickly", function () { | ||
| var goodError = new Error("haha!"); | ||
| it('should do nothing if the promise rejects quickly', function() { | ||
| var goodError = new Error('haha!'); | ||
| return Promise.delay(10) | ||
| .then(function () { | ||
| .then(function() { | ||
| throw goodError; | ||
| }) | ||
| .timeout(200) | ||
| .then(assert.fail, function (error) { | ||
| .then(assert.fail, function(error) { | ||
| assert(error === goodError); | ||
@@ -45,7 +46,7 @@ }); | ||
| it("should reject with a timeout error if the promise is too slow", function () { | ||
| it('should reject with a timeout error if the promise is too slow', function() { | ||
| var caught = false; | ||
| return Promise.delay(100) | ||
| .timeout(10) | ||
| .caught(Promise.TimeoutError, function(){ | ||
| .caught(Promise.TimeoutError, function() { | ||
| caught = true; | ||
@@ -57,7 +58,7 @@ }).then(function() { | ||
| it("should reject with a custom timeout error if the promise is too slow and msg was provided", function () { | ||
| it('should reject with a custom timeout error if the promise is too slow and msg was provided', function() { | ||
| var caught = false; | ||
| return Promise.delay(100) | ||
| .timeout(10, "custom") | ||
| .caught(Promise.TimeoutError, function(e){ | ||
| .timeout(10, 'custom') | ||
| .caught(Promise.TimeoutError, function(e) { | ||
| assert(/custom/i.test(e.message)); | ||
@@ -71,10 +72,10 @@ caught = true; | ||
| describe("delay", function () { | ||
| it("should delay fulfillment", function (done) { | ||
| describe('delay', function() { | ||
| it('should delay fulfillment', function(done) { | ||
| var pending = true; | ||
| Promise.delay(30)['finally'](function() { pending = false; }).done(); | ||
| setTimeout(function () { | ||
| setTimeout(function() { | ||
| assert(pending); | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| assert(!pending); | ||
@@ -86,8 +87,8 @@ done(); | ||
| it("should not delay rejection", function () { | ||
| it('should not delay rejection', function() { | ||
| var pending = true; | ||
| Promise.reject(5).delay(50)['finally'](function() { pending = false; }) | ||
| ['catch'](function(){}).done(); | ||
| ['catch'](function() {}).done(); | ||
| return Promise.delay(20).then(function () { | ||
| return Promise.delay(20).then(function() { | ||
| assert(!pending); | ||
@@ -97,7 +98,7 @@ }); | ||
| it("should treat a single argument as a time", function (done) { | ||
| it('should treat a single argument as a time', function(done) { | ||
| var pending = true; | ||
| Promise.delay(60)['finally'](function() { pending = false; }).done(); | ||
| setTimeout(function () { | ||
| setTimeout(function() { | ||
| assert(pending); | ||
@@ -109,21 +110,22 @@ done(); | ||
| it("should treat two arguments as a value + a time", function () { | ||
| it('should treat two arguments as a value + a time', function() { | ||
| var pending = true; | ||
| var promise = | ||
| Promise.delay("what", 40)['finally'](function() { pending = false; }); | ||
| Promise.delay('what', 40)['finally'](function() { pending = false; }); | ||
| return Promise.delay(20).then(function () { | ||
| return Promise.delay(20).then(function() { | ||
| assert(pending); | ||
| }).then(function() { | ||
| return promise; | ||
| }).then(function (value) { | ||
| }).then(function(value) { | ||
| assert(!pending); | ||
| assert(value === "what"); | ||
| assert(value === 'what'); | ||
| }); | ||
| }); | ||
| it("should delay after resolution", function () { | ||
| var promise1 = Promise.delay("what", 20); | ||
| it('should delay after resolution', function() { | ||
| var promise1 = Promise.delay('what', 20); | ||
| var promise2 = promise1.delay(40); | ||
| var pending1 = true, pending2 = true; | ||
| var pending1 = true; | ||
| var pending2 = true; | ||
| promise1 = promise1['finally'](function() { pending1 = false; }); | ||
@@ -137,7 +139,7 @@ promise2 = promise2['finally'](function() { pending2 = false; }); | ||
| return promise2; | ||
| }).then(function (value) { | ||
| }).then(function(value) { | ||
| assert(!pending2); | ||
| assert(value === "what"); | ||
| assert(value === 'what'); | ||
| }); | ||
| }); | ||
| }); |
+21
-21
@@ -1,5 +0,5 @@ | ||
| "use strict"; | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -28,6 +28,6 @@ var fulfilled = Promise.resolve.bind(Promise); | ||
| var tryy = Promise["try"].bind(Promise); | ||
| var tryy = Promise['try'].bind(Promise); | ||
| describe("Promise.try", function(){ | ||
| specify("should reject when the function throws", function() { | ||
| describe('Promise.try', function() { | ||
| specify('should reject when the function throws', function() { | ||
| var async = false; | ||
@@ -41,3 +41,3 @@ var p = tryy(thrower).then(assert.fail, function(e) { | ||
| }); | ||
| specify("should reject when the function is not a function", function() { | ||
| specify('should reject when the function is not a function', function() { | ||
| var async = false; | ||
@@ -51,3 +51,3 @@ var p = tryy(null).then(assert.fail, function(e) { | ||
| }); | ||
| specify("should call the function with the given receiver", function() { | ||
| specify('should call the function with the given receiver', function() { | ||
| var async = false; | ||
@@ -61,3 +61,3 @@ var p = tryy(receiver, obj).then(function(val) { | ||
| }); | ||
| specify("should call the function with the given value", function() { | ||
| specify('should call the function with the given value', function() { | ||
| var async = false; | ||
@@ -71,7 +71,7 @@ var p = tryy(identity, null, obj).then(function(val) { | ||
| }); | ||
| specify("should call the function with the given values", function() { | ||
| specify('should call the function with the given values', function() { | ||
| var async = false; | ||
| var p = tryy(array, null, 1, 2, 3).then(function(val) { | ||
| assert(async); | ||
| assert.deepEqual(val, [1,2,3]); | ||
| assert.deepEqual(val, [1, 2, 3]); | ||
| }); | ||
@@ -82,3 +82,3 @@ async = true; | ||
| specify("should unwrap this and arguments", function() { | ||
| specify('should unwrap this and arguments', function() { | ||
| var d = pending(); | ||
@@ -92,3 +92,3 @@ var THIS = {}; | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d.resolve(THIS); | ||
@@ -100,12 +100,12 @@ }, 10); | ||
| specify("should unwrap returned promise", function() { | ||
| specify('should unwrap returned promise', function() { | ||
| var d = pending(); | ||
| var p = tryy(function(){ | ||
| var p = tryy(function() { | ||
| return d.promise; | ||
| }).then(function(v){ | ||
| }).then(function(v) { | ||
| assert(v === 3); | ||
| }); | ||
| setTimeout(function(){ | ||
| setTimeout(function() { | ||
| d.resolve(3); | ||
@@ -116,11 +116,11 @@ }, 13); | ||
| }); | ||
| specify("should unwrap returned thenable", function() { | ||
| specify('should unwrap returned thenable', function() { | ||
| return tryy(function(){ | ||
| return tryy(function() { | ||
| return { | ||
| then: function(f, v) { | ||
| f(3); | ||
| } | ||
| }, | ||
| }; | ||
| }).then(function(v){ | ||
| }).then(function(v) { | ||
| assert(v === 3); | ||
@@ -127,0 +127,0 @@ }); |
+10
-9
@@ -1,5 +0,6 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -10,3 +11,3 @@ describe('Promise#call', function() { | ||
| test: function() { return Promise.resolve(this.foo); }, | ||
| foo: 42 | ||
| foo: 42, | ||
| }).call('test').then(function(v) { | ||
@@ -19,6 +20,6 @@ assert.deepEqual(v, 42); | ||
| return Promise.resolve({ | ||
| test: function(x, y) { return Promise.resolve(x + 2*y + this.foo); }, | ||
| foo: 42 | ||
| test: function(x, y) { return Promise.resolve(x + 2 * y + this.foo); }, | ||
| foo: 42, | ||
| }).call('test', 3, Promise.resolve(7)).then(function(v) { | ||
| assert.deepEqual(v, 3 + 2*7 + 42); | ||
| assert.deepEqual(v, 3 + 2 * 7 + 42); | ||
| }); | ||
@@ -49,3 +50,3 @@ }); | ||
| return Promise.resolve({ | ||
| test: 42 | ||
| test: 42, | ||
| }).get('test').then(function(v) { | ||
@@ -58,3 +59,3 @@ assert.deepEqual(v, 42); | ||
| return Promise.resolve({ | ||
| test: Promise.resolve(42) | ||
| test: Promise.resolve(42), | ||
| }).get('test').then(function(v) { | ||
@@ -61,0 +62,0 @@ assert.deepEqual(v, 42); |
+20
-17
@@ -1,2 +0,3 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| /* | ||
@@ -29,4 +30,4 @@ Based on When.js tests | ||
| WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -37,5 +38,5 @@ var when = Promise; | ||
| describe("when.all-test", function () { | ||
| describe('when.all-test', function() { | ||
| specify("should resolve empty input", function() { | ||
| specify('should resolve empty input', function() { | ||
| return when.all([]).then( | ||
@@ -48,3 +49,3 @@ function(result) { | ||
| specify("should resolve promise of empty input", function() { | ||
| specify('should resolve promise of empty input', function() { | ||
| return resolved([]).all().then( | ||
@@ -57,3 +58,3 @@ function(result) { | ||
| specify("should resolve values array", function() { | ||
| specify('should resolve values array', function() { | ||
| var input = [1, 2, 3]; | ||
@@ -67,3 +68,3 @@ return when.all(input).then( | ||
| specify("should resolve promise of values array", function() { | ||
| specify('should resolve promise of values array', function() { | ||
| var input = [1, 2, 3]; | ||
@@ -77,3 +78,3 @@ return resolved(input).all().then( | ||
| specify("should resolve promises array", function() { | ||
| specify('should resolve promises array', function() { | ||
| var input = [resolved(1), resolved(2), resolved(3)]; | ||
@@ -87,3 +88,3 @@ return when.all(input).then( | ||
| specify("should resolve promise of promises array", function() { | ||
| specify('should resolve promise of promises array', function() { | ||
| var input = [resolved(1), resolved(2), resolved(3)]; | ||
@@ -97,3 +98,4 @@ return resolved(input).all().then( | ||
| specify("should resolve sparse array input", function() { | ||
| specify('should resolve sparse array input', function() { | ||
| /* jshint elision: true */ | ||
| var input = [, 1, , 1, 1 ]; | ||
@@ -107,3 +109,4 @@ return when.all(input).then( | ||
| specify("should resolve promise of sparse array input", function() { | ||
| specify('should resolve promise of sparse array input', function() { | ||
| /* jshint elision: true */ | ||
| var input = [, 1, , 1, 1 ]; | ||
@@ -117,3 +120,3 @@ return resolved(input).all().then( | ||
| specify("should reject if any input promise rejects", function() { | ||
| specify('should reject if any input promise rejects', function() { | ||
| var input = [resolved(1), rejected(2), resolved(3)]; | ||
@@ -128,3 +131,3 @@ return when.all(input).then( | ||
| specify("should reject if any input promise rejects (2)", function() { | ||
| specify('should reject if any input promise rejects (2)', function() { | ||
| var input = [resolved(1), rejected(2), resolved(3)]; | ||
@@ -139,3 +142,3 @@ return resolved(input).all().then( | ||
| specify("should reject if any input promise rejects (3)", function() { | ||
| specify('should reject if any input promise rejects (3)', function() { | ||
| var input = [resolved(1), resolved(2), resolved(3)]; | ||
@@ -150,3 +153,3 @@ return rejected(input).all().then( | ||
| specify("should accept a promise for an array", function() { | ||
| specify('should accept a promise for an array', function() { | ||
| var expected, input; | ||
@@ -164,3 +167,3 @@ | ||
| specify("should reject when input promise does not resolve to array", function() { | ||
| specify('should reject when input promise does not resolve to array', function() { | ||
| var caught = false; | ||
@@ -167,0 +170,0 @@ return when.all(resolved(1)).caught(TypeError, function(e) { |
+24
-23
@@ -1,2 +0,3 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| /* | ||
@@ -29,4 +30,4 @@ Based on When.js tests | ||
| WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -42,8 +43,8 @@ var when = Promise; | ||
| defined: function(val) { | ||
| assert( typeof val === "undefined" ); | ||
| assert(typeof val === 'undefined'); | ||
| }, | ||
| equals: function( a, b ) { | ||
| assert.notDeepEqual( a, b ); | ||
| } | ||
| equals: function(a, b) { | ||
| assert.notDeepEqual(a, b); | ||
| }, | ||
| }; | ||
@@ -55,3 +56,3 @@ | ||
| return fakeResolved(callback ? callback(val) : val); | ||
| } | ||
| }, | ||
| }; | ||
@@ -64,10 +65,10 @@ } | ||
| return errback ? fakeResolved(errback(reason)) : fakeRejected(reason); | ||
| } | ||
| }, | ||
| }; | ||
| } | ||
| describe("Promise.defer", function () { | ||
| describe('Promise.defer', function() { | ||
| specify("should fulfill with an immediate value", function() { | ||
| specify('should fulfill with an immediate value', function() { | ||
| var d = when.defer(); | ||
@@ -86,3 +87,3 @@ | ||
| specify("should fulfill with fulfilled promised", function() { | ||
| specify('should fulfill with fulfilled promised', function() { | ||
| var d = when.defer(); | ||
@@ -101,3 +102,3 @@ | ||
| specify("should reject with rejected promise", function() { | ||
| specify('should reject with rejected promise', function() { | ||
| var d = when.defer(); | ||
@@ -117,3 +118,3 @@ | ||
| specify("should return a promise for the resolution value", function() { | ||
| specify('should return a promise for the resolution value', function() { | ||
| var d = when.defer(); | ||
@@ -129,3 +130,3 @@ | ||
| specify("should return a promise for a promised resolution value", function() { | ||
| specify('should return a promise for a promised resolution value', function() { | ||
| var d = when.defer(); | ||
@@ -141,3 +142,3 @@ | ||
| specify("should return a promise for a promised rejection value", function() { | ||
| specify('should return a promise for a promised rejection value', function() { | ||
| var d = when.defer(); | ||
@@ -156,3 +157,3 @@ | ||
| specify("should invoke newly added callback when already resolved", function() { | ||
| specify('should invoke newly added callback when already resolved', function() { | ||
| var d = when.defer(); | ||
@@ -171,3 +172,3 @@ | ||
| specify("should reject with an immediate value", function() { | ||
| specify('should reject with an immediate value', function() { | ||
| var d = when.defer(); | ||
@@ -187,3 +188,3 @@ | ||
| specify("should reject with fulfilled promised", function() { | ||
| specify('should reject with fulfilled promised', function() { | ||
| var d, expected; | ||
@@ -206,3 +207,3 @@ | ||
| specify("should reject with rejected promise", function() { | ||
| specify('should reject with rejected promise', function() { | ||
| var d, expected; | ||
@@ -226,3 +227,3 @@ | ||
| specify("should return a promise for the rejection value", function() { | ||
| specify('should return a promise for the rejection value', function() { | ||
| var d = when.defer(); | ||
@@ -241,3 +242,3 @@ | ||
| specify("should invoke newly added errback when already rejected", function() { | ||
| specify('should invoke newly added errback when already rejected', function() { | ||
| var d = when.defer(); | ||
@@ -249,3 +250,3 @@ | ||
| assert.fail, | ||
| function (val) { | ||
| function(val) { | ||
| assert.deepEqual(val, sentinel); | ||
@@ -252,0 +253,0 @@ } |
@@ -1,2 +0,2 @@ | ||
| "use strict"; | ||
| 'use strict'; | ||
| /* | ||
@@ -29,4 +29,4 @@ Based on When.js tests | ||
| WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -37,5 +37,5 @@ var when = Promise; | ||
| describe("when.join-test", function () { | ||
| describe('when.join-test', function() { | ||
| specify("should resolve empty input", function() { | ||
| specify('should resolve empty input', function() { | ||
| return when.join().then( | ||
@@ -48,3 +48,3 @@ function(result) { | ||
| specify("should join values", function() { | ||
| specify('should join values', function() { | ||
| return when.join(1, 2, 3).then( | ||
@@ -57,3 +57,3 @@ function(results) { | ||
| specify("should join promises array", function() { | ||
| specify('should join promises array', function() { | ||
| return when.join(resolved(1), resolved(2), resolved(3)).then( | ||
@@ -66,3 +66,3 @@ function(results) { | ||
| specify("should join mixed array", function() { | ||
| specify('should join mixed array', function() { | ||
| return when.join(resolved(1), 2, resolved(3), 4).then( | ||
@@ -75,3 +75,3 @@ function(results) { | ||
| specify("should reject if any input promise rejects", function() { | ||
| specify('should reject if any input promise rejects', function() { | ||
| return when.join(resolved(1), rejected(2), resolved(3)).then( | ||
@@ -78,0 +78,0 @@ function() { throw new Error('should not reach here'); }, |
+26
-25
@@ -1,2 +0,3 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| /* | ||
@@ -29,4 +30,4 @@ Based on When.js tests | ||
| WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -39,3 +40,3 @@ var when = Promise; | ||
| describe("when.map-test", function () { | ||
| describe('when.map-test', function() { | ||
@@ -47,10 +48,10 @@ function mapper(val) { | ||
| function deferredMapper(val) { | ||
| return delay(mapper(val), Math.random()*10); | ||
| return delay(mapper(val), Math.random() * 10); | ||
| } | ||
| specify("should map input values array", function() { | ||
| specify('should map input values array', function() { | ||
| var input = [1, 2, 3]; | ||
| return when.map(input, mapper).then( | ||
| function(results) { | ||
| assert.deepEqual(results, [2,4,6]); | ||
| assert.deepEqual(results, [2, 4, 6]); | ||
| } | ||
@@ -60,7 +61,7 @@ ); | ||
| specify("should map input promises array", function() { | ||
| specify('should map input promises array', function() { | ||
| var input = [resolved(1), resolved(2), resolved(3)]; | ||
| return when.map(input, mapper).then( | ||
| function(results) { | ||
| assert.deepEqual(results, [2,4,6]); | ||
| assert.deepEqual(results, [2, 4, 6]); | ||
| } | ||
@@ -70,7 +71,7 @@ ); | ||
| specify("should map mixed input array", function() { | ||
| specify('should map mixed input array', function() { | ||
| var input = [1, resolved(2), 3]; | ||
| return when.map(input, mapper).then( | ||
| function(results) { | ||
| assert.deepEqual(results, [2,4,6]); | ||
| assert.deepEqual(results, [2, 4, 6]); | ||
| } | ||
@@ -80,7 +81,7 @@ ); | ||
| specify("should map input when mapper returns a promise", function() { | ||
| var input = [1,2,3]; | ||
| specify('should map input when mapper returns a promise', function() { | ||
| var input = [1, 2, 3]; | ||
| return when.map(input, deferredMapper).then( | ||
| function(results) { | ||
| assert.deepEqual(results, [2,4,6]); | ||
| assert.deepEqual(results, [2, 4, 6]); | ||
| } | ||
@@ -90,6 +91,6 @@ ); | ||
| specify("should accept a promise for an array (1)", function() { | ||
| specify('should accept a promise for an array (1)', function() { | ||
| return when.map(resolved([1, resolved(2), 3]), mapper).then( | ||
| function(result) { | ||
| assert.deepEqual(result, [2,4,6]); | ||
| assert.deepEqual(result, [2, 4, 6]); | ||
| } | ||
@@ -99,6 +100,6 @@ ); | ||
| specify("should accept a promise for an array (2)", function() { | ||
| specify('should accept a promise for an array (2)', function() { | ||
| return resolved([1, resolved(2), 3]).map(mapper).then( | ||
| function(result) { | ||
| assert.deepEqual(result, [2,4,6]); | ||
| assert.deepEqual(result, [2, 4, 6]); | ||
| } | ||
@@ -108,3 +109,3 @@ ); | ||
| specify("should resolve to empty array when input promise does not resolve to an array (1)", function() { | ||
| specify('should resolve to empty array when input promise does not resolve to an array (1)', function() { | ||
| return when.map(resolved(123), mapper).then( | ||
@@ -117,3 +118,3 @@ function(result) { | ||
| specify("should resolve to empty array when input promise does not resolve to an array (2)", function() { | ||
| specify('should resolve to empty array when input promise does not resolve to an array (2)', function() { | ||
| return resolved(123).map(mapper).then( | ||
@@ -126,7 +127,7 @@ function(result) { | ||
| specify("should map input promises when mapper returns a promise", function() { | ||
| var input = [resolved(1),resolved(2),resolved(3)]; | ||
| specify('should map input promises when mapper returns a promise', function() { | ||
| var input = [resolved(1), resolved(2), resolved(3)]; | ||
| return when.map(input, mapper).then( | ||
| function(results) { | ||
| assert.deepEqual(results, [2,4,6]); | ||
| assert.deepEqual(results, [2, 4, 6]); | ||
| } | ||
@@ -136,3 +137,3 @@ ); | ||
| specify("should reject when input contains rejection", function() { | ||
| specify('should reject when input contains rejection', function() { | ||
| var input = [resolved(1), reject(2), resolved(3)]; | ||
@@ -142,3 +143,3 @@ return when.map(input, mapper).then( | ||
| function(result) { | ||
| assert( result === 2 ); | ||
| assert(result === 2); | ||
| } | ||
@@ -145,0 +146,0 @@ ); |
+46
-45
@@ -1,2 +0,3 @@ | ||
| "use strict"; | ||
| // jscs:disable maximumLineLength | ||
| 'use strict'; | ||
| /* | ||
@@ -29,4 +30,4 @@ Based on When.js tests | ||
| WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -41,3 +42,3 @@ var when = Promise; | ||
| describe("when.reduce-test", function () { | ||
| describe('when.reduce-test', function() { | ||
@@ -53,4 +54,4 @@ function plus(sum, val) { | ||
| specify("should reduce values without initial value", function() { | ||
| return when.reduce([1,2,3], plus).then( | ||
| specify('should reduce values without initial value', function() { | ||
| return when.reduce([1, 2, 3], plus).then( | ||
| function(result) { | ||
@@ -62,4 +63,4 @@ assert.deepEqual(result, 6); | ||
| specify("should reduce values with initial value", function() { | ||
| return when.reduce([1,2,3], plus, 1).then( | ||
| specify('should reduce values with initial value', function() { | ||
| return when.reduce([1, 2, 3], plus, 1).then( | ||
| function(result) { | ||
@@ -71,4 +72,4 @@ assert.deepEqual(result, 7); | ||
| specify("should reduce values with initial promise", function() { | ||
| return when.reduce([1,2,3], plus, resolved(1)).then( | ||
| specify('should reduce values with initial promise', function() { | ||
| return when.reduce([1, 2, 3], plus, resolved(1)).then( | ||
| function(result) { | ||
@@ -80,3 +81,3 @@ assert.deepEqual(result, 7); | ||
| specify("should reduce promised values without initial value", function() { | ||
| specify('should reduce promised values without initial value', function() { | ||
| var input = [resolved(1), resolved(2), resolved(3)]; | ||
@@ -90,3 +91,3 @@ return when.reduce(input, plus).then( | ||
| specify("should reduce promised values with initial value", function() { | ||
| specify('should reduce promised values with initial value', function() { | ||
| var input = [resolved(1), resolved(2), resolved(3)]; | ||
@@ -100,3 +101,3 @@ return when.reduce(input, plus, 1).then( | ||
| specify("should reduce promised values with initial promise", function() { | ||
| specify('should reduce promised values with initial promise', function() { | ||
| var input = [resolved(1), resolved(2), resolved(3)]; | ||
@@ -110,3 +111,3 @@ return when.reduce(input, plus, resolved(1)).then( | ||
| specify("should reduce empty input with initial value", function() { | ||
| specify('should reduce empty input with initial value', function() { | ||
| var input = []; | ||
@@ -120,3 +121,3 @@ return when.reduce(input, plus, 1).then( | ||
| specify("should reduce empty input with initial promise", function() { | ||
| specify('should reduce empty input with initial promise', function() { | ||
| return when.reduce([], plus, resolved(1)).then( | ||
@@ -129,3 +130,3 @@ function(result) { | ||
| specify("should reject when input contains rejection", function() { | ||
| specify('should reject when input contains rejection', function() { | ||
| var input = [resolved(1), rejected(2), resolved(3)]; | ||
@@ -140,3 +141,3 @@ return when.reduce(input, plus, resolved(1)).then( | ||
| specify("should reject with empty array", function() { | ||
| specify('should reject with empty array', function() { | ||
| var caught = false; | ||
@@ -150,4 +151,4 @@ return when.reduce([], plus).caught(TypeError, function(e) { | ||
| specify("should reduce to initial value with empty array", function() { | ||
| return when.reduce([], plus, sentinel).then(function(r){ | ||
| specify('should reduce to initial value with empty array', function() { | ||
| return when.reduce([], plus, sentinel).then(function(r) { | ||
| assert(r === sentinel); | ||
@@ -157,3 +158,3 @@ }); | ||
| specify("should reduce in left-to-right order", function() { | ||
| specify('should reduce in left-to-right order', function() { | ||
| return when.reduce([later(1), later(2), later(3)], plus, '').then( | ||
@@ -166,3 +167,3 @@ function(result) { | ||
| specify("should accept a promise for an array", function() { | ||
| specify('should accept a promise for an array', function() { | ||
| return when.reduce(resolved([1, 2, 3]), plus, '').then( | ||
@@ -175,3 +176,3 @@ function(result) { | ||
| specify("should resolve to initialValue when input promise does not resolve to an array", function() { | ||
| specify('should resolve to initialValue when input promise does not resolve to an array', function() { | ||
| return when.reduce(resolved(123), plus, 1).then( | ||
@@ -184,3 +185,3 @@ function(result) { | ||
| specify("should provide correct basis value", function() { | ||
| specify('should provide correct basis value', function() { | ||
| function insertIntoArray(arr, val, i) { | ||
@@ -193,3 +194,3 @@ arr[i] = val; | ||
| function(result) { | ||
| assert.deepEqual(result, [1,2,3]); | ||
| assert.deepEqual(result, [1, 2, 3]); | ||
| } | ||
@@ -200,3 +201,3 @@ ); | ||
| describe("when.reduceRight-test", function () { | ||
| describe('when.reduceRight-test', function() { | ||
@@ -212,4 +213,4 @@ function plus(sum, val) { | ||
| specify("should reduceRight values without initial value", function() { | ||
| return when.reduceRight([1,2,3], plus).then( | ||
| specify('should reduceRight values without initial value', function() { | ||
| return when.reduceRight([1, 2, 3], plus).then( | ||
| function(result) { | ||
@@ -221,4 +222,4 @@ assert.deepEqual(result, 6); | ||
| specify("should reduceRight values with initial value", function() { | ||
| return when.reduceRight([1,2,3], plus, 1).then( | ||
| specify('should reduceRight values with initial value', function() { | ||
| return when.reduceRight([1, 2, 3], plus, 1).then( | ||
| function(result) { | ||
@@ -230,4 +231,4 @@ assert.deepEqual(result, 7); | ||
| specify("should reduceRight values with initial promise", function() { | ||
| return when.reduceRight([1,2,3], plus, resolved(1)).then( | ||
| specify('should reduceRight values with initial promise', function() { | ||
| return when.reduceRight([1, 2, 3], plus, resolved(1)).then( | ||
| function(result) { | ||
@@ -239,3 +240,3 @@ assert.deepEqual(result, 7); | ||
| specify("should reduceRight promised values without initial value", function() { | ||
| specify('should reduceRight promised values without initial value', function() { | ||
| var input = [resolved(1), resolved(2), resolved(3)]; | ||
@@ -249,3 +250,3 @@ return when.reduceRight(input, plus).then( | ||
| specify("should reduceRight promised values with initial value", function() { | ||
| specify('should reduceRight promised values with initial value', function() { | ||
| var input = [resolved(1), resolved(2), resolved(3)]; | ||
@@ -259,3 +260,3 @@ return when.reduceRight(input, plus, 1).then( | ||
| specify("should reduceRight promised values with initial promise", function() { | ||
| specify('should reduceRight promised values with initial promise', function() { | ||
| var input = [resolved(1), resolved(2), resolved(3)]; | ||
@@ -269,3 +270,3 @@ return when.reduceRight(input, plus, resolved(1)).then( | ||
| specify("should reduceRight empty input with initial value", function() { | ||
| specify('should reduceRight empty input with initial value', function() { | ||
| var input = []; | ||
@@ -279,3 +280,3 @@ return when.reduceRight(input, plus, 1).then( | ||
| specify("should reduceRight empty input with initial promise", function() { | ||
| specify('should reduceRight empty input with initial promise', function() { | ||
| return when.reduceRight([], plus, resolved(1)).then( | ||
@@ -288,3 +289,3 @@ function(result) { | ||
| specify("should reject when input contains rejection", function() { | ||
| specify('should reject when input contains rejection', function() { | ||
| var input = [resolved(1), rejected(2), resolved(3)]; | ||
@@ -299,3 +300,3 @@ return when.reduceRight(input, plus, resolved(1)).then( | ||
| specify("should reject with empty array", function() { | ||
| specify('should reject with empty array', function() { | ||
| var caught = false; | ||
@@ -309,4 +310,4 @@ return when.reduceRight([], plus).caught(TypeError, function(e) { | ||
| specify("should reduceRight to initial value with empty array", function() { | ||
| return when.reduceRight([], plus, sentinel).then(function(r){ | ||
| specify('should reduceRight to initial value with empty array', function() { | ||
| return when.reduceRight([], plus, sentinel).then(function(r) { | ||
| assert(r === sentinel); | ||
@@ -316,3 +317,3 @@ }); | ||
| specify("should reduceRight in right-to-left order", function() { | ||
| specify('should reduceRight in right-to-left order', function() { | ||
| return when.reduceRight([later(1), later(2), later(3)], plus, '').then( | ||
@@ -325,3 +326,3 @@ function(result) { | ||
| specify("should accept a promise for an array", function() { | ||
| specify('should accept a promise for an array', function() { | ||
| return when.reduceRight(resolved([1, 2, 3]), plus, '').then( | ||
@@ -334,3 +335,3 @@ function(result) { | ||
| specify("should resolve to initialValue when input promise does not resolve to an array", function() { | ||
| specify('should resolve to initialValue when input promise does not resolve to an array', function() { | ||
| return when.reduceRight(resolved(123), plus, 1).then( | ||
@@ -343,3 +344,3 @@ function(result) { | ||
| specify("should provide correct basis value", function() { | ||
| specify('should provide correct basis value', function() { | ||
| function insertIntoArray(arr, val, i) { | ||
@@ -352,3 +353,3 @@ arr[i] = val; | ||
| function(result) { | ||
| assert.deepEqual(result, [1,2,3]); | ||
| assert.deepEqual(result, [1, 2, 3]); | ||
| } | ||
@@ -355,0 +356,0 @@ ); |
+13
-13
@@ -1,2 +0,2 @@ | ||
| "use strict"; | ||
| 'use strict'; | ||
| /* | ||
@@ -29,4 +29,4 @@ Based on When.js tests | ||
| WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ | ||
| var assert = require("assert"); | ||
| require('../'); | ||
| var assert = require('assert'); | ||
| var Promise = require('../'); | ||
@@ -37,7 +37,7 @@ var when = Promise; | ||
| describe("when.spread-test", function () { | ||
| describe('when.spread-test', function() { | ||
| var slice = [].slice; | ||
| specify("should return a promise", function() { | ||
| assert( typeof (resolved([1,2]).spread().then) === "function"); | ||
| specify('should return a promise', function() { | ||
| assert(typeof (resolved([1, 2]).spread().then) === 'function'); | ||
| // return a promise from all synchronous tests, for consistency | ||
@@ -47,3 +47,3 @@ return resolved(); | ||
| specify("should apply onFulfilled with array as argument list", function() { | ||
| specify('should apply onFulfilled with array as argument list', function() { | ||
| var expected = [1, 2, 3]; | ||
@@ -55,3 +55,3 @@ return when.resolve(expected).spread(function() { | ||
| specify("should resolve array contents", function() { | ||
| specify('should resolve array contents', function() { | ||
| var expected = [when.resolve(1), 2, when.resolve(3)]; | ||
@@ -63,3 +63,3 @@ return when.resolve(expected).spread(function() { | ||
| specify("should reject if any item in array rejects (1)", function() { | ||
| specify('should reject if any item in array rejects (1)', function() { | ||
| var expected = [when.resolve(1), 2, when.reject(3)]; | ||
@@ -72,3 +72,3 @@ return when.resolve(expected) | ||
| specify("should reject if any item in array rejects (2)", function() { | ||
| specify('should reject if any item in array rejects (2)', function() { | ||
| var expected = [when.resolve(1), 2, when.resolve(3)]; | ||
@@ -81,3 +81,3 @@ return when.reject(expected) | ||
| specify("should apply onFulfilled with array as argument list", function() { | ||
| specify('should apply onFulfilled with array as argument list', function() { | ||
| var expected = [1, 2, 3]; | ||
@@ -89,3 +89,3 @@ return when.resolve(when.resolve(expected)).spread(function() { | ||
| specify("should resolve array contents", function() { | ||
| specify('should resolve array contents', function() { | ||
| var expected = [when.resolve(1), 2, when.resolve(3)]; | ||
@@ -97,3 +97,3 @@ return when.resolve(when.resolve(expected)).spread(function() { | ||
| specify("should resolve array contents in rejection", function() { | ||
| specify('should resolve array contents in rejection', function() { | ||
| var expected = [when.resolve(1), 2, when.resolve(3)]; | ||
@@ -100,0 +100,0 @@ return when.reject(expected).spread(assert.fail, function() { |
Sorry, the diff of this file is not supported yet
195312
1.94%36
5.88%4540
1.23%1471
2.58%4
33.33%- Removed