Comments (2)
I'm hesitating whether this is a valid use case we should be supporting. What are the use cases to actually replace the entire body of the document? This isn't something done as part of frameworks and since there's a workaround to this, I'm not sure we should be providing a solution as part of our code.
from dom-testing-library.
I was able to get this to work in #1311.
But right now the types are failing and I'm uncertain how to resolve them.
I'll copy the rationale here which I feel better explains my use case:
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:
We try to only expose methods and utilities that encourage you to
write tests that closely resemble how your web pages are used.
To assist with this, parts of my integration testing environment involve
a 2-step process:
- Run a command to dump the HTML documents rendered by the backend.
- Load those dumps into a Jest test environment to assert JavaScript
behavior.
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:
const content = loadHTML(...);
const tmpDom = new jsdom.JSDOM(content);
const tmpDocument = tmpDom.window.document;
// Replace the global document with the one from the backend.
document.documentElement.replaceWith(document.adoptNode(tmpDocument.documentElement));
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.
from dom-testing-library.
Related Issues (20)
- Having a <p> inside a <label> breaks the query HOT 2
- Support complex aria-labelledby queries HOT 1
- Support abstract roles HOT 9
- findByRole() finds no candidates HOT 13
- getByText not working with multiline text
- `waitFor` doesn't advance time when using `jest` fake timers without injecting globals HOT 4
- `getByRole('insertion')` and `getByRole('deletion')` do not match semantic `<del>` and `<ins>` tags HOT 6
- getByRole('caption') does not find caption element HOT 12
- Images with an empty alt attribute are not being assigned `presentation` role (and are still being found by testing library even though they are hidden from the accessibility tree) HOT 4
- fireEvent doesn't work in pointer event HOT 2
- Github actions - tests pass but execution fails on Process completed with exit code 1. HOT 2
- *ByRole form seems not to find <form /> elements HOT 5
- v8.20.1 - invalid syntax reported by esprima-fb HOT 1
- ByRole doesn't find SVG's graphics-document role HOT 3
- when running vitest(using react-testing-library-dom) in git action, action exceeded the maximum execution time of xx minutes HOT 7
- Test fails if not wrapped into waitFor HOT 6
- can't run CodeSandbox tests (issue converting to devbox) HOT 3
- Queries having multiple types HOT 1
- getByText throwing when throwSuggestions is enforced recommending ambiguous getByRole('paragraph') approach. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dom-testing-library.