Permalink
Browse files

Updates spectacular async to use an optional timeout

  • Loading branch information...
1 parent a0f8411 commit 694f1453100adcc1ba4f738a183371c867e1d555 Daniel Neighman committed with Jan 15, 2010
Showing with 30 additions and 1 deletion.
  1. +11 −0 spec_example.js
  2. +19 −1 tacular.js
View
@@ -16,4 +16,15 @@ describe("A test", function(){
})
setTimeout(function(){ promise.emitSuccess() }, 500);
});
+
+ it("should fail a timeout", 300, function(promise){
+ promise.addCallback(function(){
+ assert(true);
+ })
+ setTimeout(function(){ promise.emitSuccess() }, 1000);
+ });
+
+ it("Should pass simple sync tests after async ones", function(){
+ assert(true);
+ });
});
View
@@ -40,6 +40,14 @@
* setTimeout(function(){ promise.emitSuccess() }, 500);
* });
*
+ * // Supply a name, timeout and function. Only used in the async case
+ *
+ * it("should fail a timeout", 300, function(promise){
+ * promise.addCallback(function(){
+ * assert(true);
+ * })
+ * setTimeout(function(){ promise.emitSuccess() }, 1000);
+ * });
* });
*
* Copyright 2009, Jon Crosby, MIT Licensed
@@ -65,6 +73,13 @@ process.mixin(require('sys'));
};
var it = function(name, func) {
+ var timeout = undefined;
+
+ if(arguments.length == 3){
+ timeout = func;
+ func = arguments[2];
+ }
+
specCount++;
specStack.push(name);
if (specVerbose) print("\n "+name+" : ");
@@ -74,8 +89,11 @@ process.mixin(require('sys'));
func();
} else {
var promise = new process.Promise();
+
+ if(timeout)
+ promise.timeout(timeout);
+
func(promise);
- promise.addErrback(function(e){ throw e });
promise.wait();
}
}

0 comments on commit 694f145

Please sign in to comment.