Skip to content

Instantly share code, notes, and snippets.

@juandopazo
Created May 2, 2013 22:22
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 juandopazo/5505936 to your computer and use it in GitHub Desktop.
Save juandopazo/5505936 to your computer and use it in GitHub Desktop.
Something that I keep writing for asynchronous tests
suite.add(new Y.Test.Case({
name: 'foo',
'some test': function () {
var test = this;
Y.io('foo', function (id, response) {
// this is just boilerplate
test.resume(function () {
Y.Test.Assert.areEqual('foo', response.responseText);
});
});
test.wait(1000);
}
}));
// I'm tempted with doing this
Y.Test.Case.prototype.next = function (fn) {
var test = this;
return function () {
var args = arguments;
test.resume(function () {
fn.apply(this, args);
});
};
};
// so now the boilerplate changes to this
'some tst': function () {
var test = this;
Y.io('foo', test.next(function (id, response) {
Y.Test.Assert.areEqual('foo', response.responseText);
}));
test.wait(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment