Skip to content

Instantly share code, notes, and snippets.

@wycats

wycats/async.js Secret

Created October 15, 2012 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wycats/2138c7bf20da83e823e8 to your computer and use it in GitHub Desktop.
Save wycats/2138c7bf20da83e823e8 to your computer and use it in GitHub Desktop.
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);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment