Skip to content

Commit 78a4b4a

Browse files
committed
Added test for finally and always
1 parent 0ca5d8b commit 78a4b4a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/promise.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,48 @@ describe('promise', function() {
1111
});
1212
});
1313

14+
describe('always and finally', function(){
15+
it('should call always and finally', function(done){
16+
var p = new AV.Promise(function(resolve, reject) {
17+
resolve(42);
18+
});
19+
var counts= 0;
20+
var completefn = function() {
21+
if(counts == 2) done();
22+
};
23+
p.finally(function(ret) {
24+
expect(ret).to.be(42);
25+
counts++;
26+
completefn();
27+
});
28+
p.always(function(ret) {
29+
expect(ret).to.be(42);
30+
counts++;
31+
completefn();
32+
});
33+
});
34+
35+
it('should call always and finally when reject.', function(done){
36+
var p = new AV.Promise(function(resolve, reject) {
37+
reject(42);
38+
});
39+
var counts= 0;
40+
var completefn = function() {
41+
if(counts == 2) done();
42+
};
43+
p.finally(function(ret) {
44+
expect(ret).to.be(42);
45+
counts++;
46+
completefn();
47+
});
48+
p.always(function(ret) {
49+
expect(ret).to.be(42);
50+
counts++;
51+
completefn();
52+
});
53+
});
54+
});
55+
1456
describe('AV.Promise#catch', function(){
1557
it('sould be called', function(done) {
1658
var promise = new AV.Promise(function(resolve, reject) {

0 commit comments

Comments
 (0)