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

feat($q): add resolve function #11987

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/ng/q.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,19 @@ function qFactory(nextTick, exceptionHandler) {
return result.promise.then(callback, errback, progressBack);
};

/**
* @ngdoc method
* @name $q#resolve
* @kind function
*
* @description
* Alias of {@link ng.$q#when when} to maintain naming consistency with ES6.
*
* @param {*} value Value or a promise
* @returns {Promise} Returns a promise of the passed value or promise
*/
var resolve = when;

/**
* @ngdoc method
* @name $q#all
Expand Down Expand Up @@ -565,6 +578,7 @@ function qFactory(nextTick, exceptionHandler) {
$Q.defer = defer;
$Q.reject = reject;
$Q.when = when;
$Q.resolve = resolve;
$Q.all = all;

return $Q;
Expand Down
8 changes: 8 additions & 0 deletions test/ng/qSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,14 @@ describe('q', function() {
});


describe('resolve', function() {
it('should be an alias of the "when" function', function() {
expect(q.resolve).toBeDefined();
expect(q.resolve).toEqual(q.when);
});
});


describe('optional callbacks', function() {
it('should not require success callback and propagate resolution', function() {
q.when('hi', null, error()).then(success(2), error());
Expand Down