Created
May 2, 2013 22:22
-
-
Save juandopazo/5505936 to your computer and use it in GitHub Desktop.
Something that I keep writing for asynchronous tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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