-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03-usingPromised.test.js
60 lines (48 loc) · 1.37 KB
/
03-usingPromised.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
if (typeof define !== 'function') { var define = require('amdefine')(module); }
define("03-usingPromised.test", ["buster", "q", "./02-promiseAndCallback", "./03-usingPromised"], function(buster, Q, htmlLib, libClient) {
buster.testCase("03", {
"should replace a with b in text (callback)": function(done)
{
var stub = this.stub(htmlLib, "getHtml")
.withArgs("en", "one")
.yields(null, "a");
libClient.withCallback(function(html){
expect(stub).toHaveBeenCalledOnce();
expect(html).toEqual("b");
done();
});
},
"should replace a with b in text (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.withPromise(function(html){
expect(stub).toHaveBeenCalledOnce();
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();
}
});
});