function AjaxWaitTest::testUntrackedXhr

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/FunctionalJavascriptTests/AjaxWaitTest.php \Drupal\FunctionalJavascriptTests\AjaxWaitTest::testUntrackedXhr()

Tests that an untracked XHR triggers a deprecation error.

File

core/tests/Drupal/FunctionalJavascriptTests/AjaxWaitTest.php, line 36

Class

AjaxWaitTest
Tests that unnecessary or untracked XHRs will cause a test failure.

Namespace

Drupal\FunctionalJavascriptTests

Code

public function testUntrackedXhr() : void {
  $this->getSession()
    ->executeScript(<<<JS
let xhr = new XMLHttpRequest();
xhr.open('GET', '/foobar');
xhr.send();
JS
);
  $this->expectException(\RuntimeException::class);
  $this->expectExceptionMessage('0 XHR requests through jQuery, but 1 observed in the browser — this requires js_testing_ajax_request_test.js to be updated.');
  $this->assertSession()
    ->assertExpectedAjaxRequest(1, 500);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.