Skip to content

Commit

Permalink
Merge pull request kriskowal#130 from ForbesLindesay/thenresolve
Browse files Browse the repository at this point in the history
Add `thenResolve` as per kriskowal#108
  • Loading branch information
domenic committed Oct 25, 2012
2 parents 16c913d + 26c3b41 commit ed6ef16
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions q.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,10 @@ makePromise.prototype.then = function (fulfilled, rejected, progressed) {
return when(this, fulfilled, rejected, progressed);
};

makePromise.prototype.thenResolve = function (value) {
return when(this, function () { return value; });
};

// Chainable methods
array_reduce(
[
Expand Down
32 changes: 32 additions & 0 deletions spec/q-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,38 @@ describe("done", function () {
});
});

describe("thenResolve", function () {
describe("Resolving with an object", function () {
it("returns a promise for that object once the promise is resolved", function () {
var waited = false;
Q.delay(20)
.then(function () {
waited = true;
})
.thenResolve('foo')
.then(function (val) {
expect(waited).toBe(true);
expect(val).toBe('foo');
});
});
});

describe("Resolving with an promise", function () {
it("returns a promise for the result of that promise once the promise is resolved", function () {
var waited = false;
Q.delay(20)
.then(function () {
waited = true;
})
.thenResolve(Q.resolve('foo'))
.then(function (val) {
expect(waited).toBe(true);
expect(val).toBe('foo');
});
});
});
});

describe("thenables", function () {

it("assimilates a thenable with fulfillment with resolve", function () {
Expand Down

0 comments on commit ed6ef16

Please sign in to comment.