Skip to content

Commit

Permalink
support returning crappy promises from within a jasmine-promise spec
Browse files Browse the repository at this point in the history
  • Loading branch information
rictic committed Nov 29, 2012
1 parent aa5155c commit 76cee05
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions spec/lib/jasmine-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jasmine.Block.prototype.execute = function (onComplete) {
// It seems Jasmine likes to return the suite if you pass it anything.
// So make sure it's a promise first.
if (result && typeof result.then === "function") {
result.timeout(500).then(function () {
Q.timeout(result, 500).then(function () {
onComplete();
}, function (error) {
spec.fail(error);
Expand Down Expand Up @@ -52,15 +52,40 @@ describe('jasmine-promise', function() {
setTimeout(function() {deferred.resolve();}, 100);
return deferred.promise;
});
// These are expected to fail. Remove the x from xit to test that.
xit('fails if the deferred is rejected', function() {
var deferred = Q.defer();
deferred.reject();
return deferred.promise;
it('lets specs that return nothing pass', function() {

});
xit('fails if the deferred takes too long to resolve', function() {
var deferred = Q.defer();
setTimeout(function() {deferred.resolve()}, 5 * 1000);
return deferred.promise;
it('lets specs that return non-promises pass', function() {
return {'some object': 'with values'};
});
it('works ok with specs that return crappy non-Q promises', function() {
return {
'then': function(callback) {
callback();
}
}
});
// These are expected to fail. Remove the x from xdescribe to test that.
describe('failure cases (expected to fail)', function() {
it('fails if the deferred is rejected', function() {
var deferred = Q.defer();
deferred.reject();
return deferred.promise;
});
it('fails if the deferred takes too long to resolve', function() {
var deferred = Q.defer();
setTimeout(function() {deferred.resolve()}, 5 * 1000);
return deferred.promise;
});
it('fails if a returned crappy non-Q promise is rejected', function() {
return {
'then': function(_, callback) {callback()}
}
});
it('fails if a returned crappy promise is never resolved', function() {
return {
'then': function() {}
}
});
})
});

0 comments on commit 76cee05

Please sign in to comment.