HTML-Based Tests
Learn how to use the jsdom library with Jest to test HTML elements and interactions.
We'll cover the following
Jest uses a library named jsdom to allow for testing HTML elements and interactions. The jsdom is not an actual browser; it is a library that implements the JavaScript
Running a full internet browser generally assumes that the tests are running on a standard computer and, as such, have an actual screen. This means that virtual machines that run tests must be configured with a screen, which adds the extra requirement of having a screen driver that can run at the required resolution.
Checking DOM updates
With jsdom
and jquery
installed, we can write a test that checks whether the DOM has been updated. Consider the following code:
Get hands-on with 1400+ tech skills courses.