Writing a functional JavaScript test
Assume that you now have one last request. You have been asked to use AJAX to display the value from the Camel Case formatter 3 seconds after a user has visited a page.
Testing this requires using an actual browser such as Google Chrome. Checking anything that involves AJAX, cookies, user interactions, or the DOM cannot be done with a regular functional test.
Fortunately, writing a functional JavaScript test is not all that different; we just extend from a different base class for the test – WebDriverTestBase
instead of BrowserTestBase
.
Chrome and Selenium required
If you use DDEV, Lando, Docksal, or other ready made tools to run Drupal locally, check their documentation on how to best integrate Chrome and Selenium for functional JavaScript tests. They all have variations in approach to installing them.
How to do it…
In your tests/src
directory, create a new directory named FunctionalJavascript
. Within that new directory...