Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
refactor($q): make $q Promises A+ v1.1 compilant
Browse files Browse the repository at this point in the history
The Promises A+ 1.1 spec introduces new constraints that would cause $q to fail,
particularly specs 2.3.1 and 2.3.3.

Newly satisfied requirements:

 * "then" functions that return the same fulfilled/rejected promise 
	will fail with a TypeError
 * Support for edge cases where "then" is a value other than function

Full 1.1 spec: https://github.com/promises-aplus/promises-spec/tree/1.1.0

This commit also modifies the adapter to use "resolve" method instead of "fulfill"
  • Loading branch information
lgalfaso authored and jeffbcross committed Aug 21, 2014
1 parent a603e20 commit 6a2b612
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 188 deletions.
7 changes: 4 additions & 3 deletions lib/promises-aplus/promises-aplus-test-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@

var isFunction = function isFunction(value){return typeof value == 'function';};
var isPromiseLike = function isPromiseLike(obj) {return obj && isFunction(obj.then);};
var isObject = function isObject(value){return value != null && typeof value === 'object';};

var $q = qFactory(process.nextTick, function noopExceptionHandler() {});

exports.fulfilled = $q.resolve;
exports.resolved = $q.resolve;
exports.rejected = $q.reject;
exports.pending = function () {
exports.deferred = function () {
var deferred = $q.defer();

return {
promise: deferred.promise,
fulfill: deferred.resolve,
resolve: deferred.resolve,
reject: deferred.reject
};
};
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"protractor": "1.0.0",
"yaml-js": "~0.0.8",
"rewire": "1.1.3",
"promises-aplus-tests": "~1.3.2",
"promises-aplus-tests": "~2.0.4",
"semver": "~2.1.0",
"lodash": "~2.1.0",
"browserstacktunnel-wrapper": "~1.1.1",
Expand Down
Loading

0 comments on commit 6a2b612

Please sign in to comment.