diff --git a/lib/behat/behat_base.php b/lib/behat/behat_base.php index 99dd99e3812..550745cbb19 100644 --- a/lib/behat/behat_base.php +++ b/lib/behat/behat_base.php @@ -807,11 +807,6 @@ EOF; * @return bool Whether any JS is still pending completion. */ public function wait_for_pending_js() { - if (!$this->running_javascript()) { - // JS is not available therefore there is nothing to wait for. - return false; - } - return static::wait_for_pending_js_in_session($this->getSession()); } @@ -822,6 +817,11 @@ EOF; * @return bool Whether any JS is still pending completion. */ public static function wait_for_pending_js_in_session(Session $session) { + if (!self::running_javascript_in_session($session)) { + // JS is not available therefore there is nothing to wait for. + return false; + } + // We don't use behat_base::spin() here as we don't want to end up with an exception // if the page & JSs don't finish loading properly. for ($i = 0; $i < self::get_extended_timeout() * 10; $i++) {