You are here

public function JavascriptErrorsTest::testJavascriptErrors in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/JavascriptErrorsTest.php \Drupal\FunctionalJavascriptTests\JavascriptErrorsTest::testJavascriptErrors()

Tests that JavaScript console errors will result in a test failure.

File

core/tests/Drupal/FunctionalJavascriptTests/JavascriptErrorsTest.php, line 27

Class

JavascriptErrorsTest
Tests that Drupal.throwError will cause a test failure.

Namespace

Drupal\FunctionalJavascriptTests

Code

public function testJavascriptErrors() : void {

  // Visit page that will throw a JavaScript console error.
  $this
    ->drupalGet('js_errors_test');

  // Ensure that errors from previous page loads will be
  // detected.
  $this
    ->drupalGet('user');
  $this
    ->expectException(AssertionFailedError::class);
  $this
    ->expectExceptionMessageMatches('/^Error: A manually thrown error/');

  // Manually call the method under test, as it cannot be caught by PHPUnit
  // when triggered from assertPostConditions().
  $this
    ->failOnJavaScriptErrors();
}