Skip to content

Commit

Permalink
Still wait for ajax calls in case there's another one
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Mar 25, 2020
1 parent 92ae9e9 commit 59b1fd2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/acceptance/customCommands/waitForOutstandingAjaxCalls.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const sleepWhenOutstandingAjaxCalls = function (result) {
const sleepWhenOutstandingAjaxCalls = function (result, retryWithZero) {
// sleep in all cases, because even with zero calls we don't know if there isn't
// one that might start in the next tick, so to be sure sleep again
this.pause(this.globals.waitForConditionPollInterval)
if (result.value > 0) {
this.pause(this.globals.waitForConditionPollInterval)
this.waitForOutstandingAjaxCalls()
this.waitForOutstandingAjaxCalls(true)
} else if (retryWithZero) {
// retry in case another call just started
this.waitForOutstandingAjaxCalls(false)
}
}

exports.command = function () {
exports.command = function (retryWithZero = true) {
// init the ajax counter if it hasn't been initialized yet
this.execute('return (typeof window.activeAjaxCount === "undefined")', [], function (result) {
if (result.value === true) {
Expand All @@ -14,7 +19,7 @@ exports.command = function () {
})

this.execute(
'return window.activeAjaxCount', [], sleepWhenOutstandingAjaxCalls
'return window.activeAjaxCount', [], (result) => sleepWhenOutstandingAjaxCalls.call(this, result, retryWithZero)
)
return this
}

0 comments on commit 59b1fd2

Please sign in to comment.