secret
Created

  • Download Gist
async.js
JavaScript
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
test("something", function() {
expect(1);
stop();
setTimeout(function() {
start();
ok(true);
}, 1000);
});
 
// must() returns a function that MUST be called (simple impl: stop() and
// wrap the function with a start())
 
test("something", function() {
setTimeout(must(function() {
ok(true);
}), 1000)
Ember.something(mustNot);
})
 
// the basic idea is that often you use expect() simply to assert that some
// function is actually called (or not called).
 
must = function(callback) {
stop();
return function() {
start();
callback.apply(this, arguments);
}
};
 
mustNot = function() {
return function() {
ok(false, "WAT");
}
};
 
// this is for cases where you basically need a function that throws...
// perhaps there could be some async version with a timeout?
 
mustNot = function(timeout) {
// incorrect implementation
stop();
 
var f = function() {
ok(false, "WAT");
};
var timer = setTimeout(f, timeout);
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.