Open jdufresne opened 5 months ago
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit 430e9528b0ebbe5d5417dc794f6f81547f0f84e9:
Sandbox | Source |
---|---|
react-testing-library-examples | Configuration |
Right now this fails type checks with the errors:
Error: [typecheck] src/screen.ts(54,19): error TS7019: Rest parameter 'args' implicitly has an 'any[]' type.
Error: [typecheck] src/screen.ts(61,30): error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter.
I'm uncertain how to best resolve this.
What:
The screen utility no longer caches the body element at import time. When the body or entire HTML document changes with replaceWith(), the screen utility continues to operate on the global value.
Why:
Closes https://github.com/testing-library/dom-testing-library/issues/1310
My integration testing environment strives to creates testing scenarios that are as realistic to production as possible. This aligns with the library's guiding principles:
To assist with this, parts of my integration testing environment involve a 2-step process:
Loading the HTML document in Jest is a challenge as the global HTML document is setup by jest-environment-jsdom ahead of the test running. To make this work well, the environment "replaces" the jsdom HTML document like:
This works out great in practice for me. The JavaScript is tested against real HTML documents rather than fabricated ones for the test. In the event that the backend changes how elements are rendered that, the integration tests will expose this and force a fix to make the two compatible.
With this change, the screen utility is now usable as a convenience.
How:
Rather than caching the document.body at import time, screen now dynamically uses the most up date value on the global document.
Checklist: