Permalink
Browse files

promises all the way

  • Loading branch information...
1 parent fd3aaf3 commit 406d3afc587f032bde6a906079e88b1da3108ca3 @dominykas dominykas committed Oct 1, 2012
Showing with 29 additions and 0 deletions.
  1. +9 −0 03-usingPromised.js
  2. +20 −0 03-usingPromised.test.js
View
@@ -13,6 +13,15 @@ define(["./02-promiseAndCallback"], function(htmlLib){
}).end();
},
+ withPromisePromise: function()
+ {
+ return htmlLib
+ .getHtml("en", "one")
+ .then(function(html){
+ return html.replace("a", "b");
+ });
+ },
+
withCallback: function(callback)
{
htmlLib.getHtml("en", "one", function(e, html){
View
@@ -33,6 +33,26 @@ define("03-usingPromised.test", ["buster", "q", "./02-promiseAndCallback", "./03
expect(html).toEqual("b");
done();
});
+ },
+
+ "should replace a with b in text (promise+promise)": function(done)
+ {
+ var deferred = Q.defer();
+ setTimeout(function(){
+ deferred.resolve("a");
+ }, 50);
+
+ var stub = this.stub(htmlLib, "getHtml")
+ .withArgs("en", "one")
+ .returns(deferred.promise);
+
+ libClient
+ .withPromisePromise()
+ .then(function(html){
+ expect(stub).toHaveBeenCalledOnce();
+ expect(html).toEqual("b");
+ })
+ .fin(done).end();
}
});

0 comments on commit 406d3af

Please sign in to comment.