Section9: Testing & the DOM(Frontend Javascript Testing)
Accessing The DOM from Inside Tests
- DOM vs NodeJS Environment
- Accessing the DOM
- Specialized Libraries
Should set testing environment in package.json or right in the single file as jsdom or happy-dom for emulation.
Set up testing to access html page content rendered at document of virtual window.
fs and path are still available because all the Node APIs available inside the test files.
the Dom is only emulated virtually.
Remember that we are using same document for tests. Thus, should reset before each test.
if building more complex front-end apps, the features provided by JS DOM, Happy DOM might suffice or might be a bit too clunky. means too much code to write to select elements.
In this case, Third party Library, Testing Library is recommended.
This is awesome for Unit tests and integration tests for front-end.
It also supports all popular libraries such as DOM Testing library, React Testing Library, Native Testing Library and so on.