Skip to content

Instantly share code, notes, and snippets.

@asciidisco
Created November 15, 2013 13:35
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 asciidisco/7484405 to your computer and use it in GitHub Desktop.
Save asciidisco/7484405 to your computer and use it in GitHub Desktop.
dalek_waitFor.js
// you app code
window.qa = {};
$.get('foobar.php', function (data) {
// this line could be removed during the build
window.qa.requestFooBar = true;
});
// in your dalek test
'waitFor ajax': function (test) {
test.waitFor(function () {
return !!window.qa.requestFooBar;
}, 10000)
// do something after the request finished
.done();
}
// or if you like promises
var window.request = $.get('foobar.php', function () {});
// in your dalek test
'waitFor ajax (with promises)': function (test) {
test.waitFor(function () {
var isDone = false;
window.request.done(function () { isDone = true; });
return isDone;
}, 10000)
// do something after the request finished
.done();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment