Comments (4)
As solution to this specific use-case, is something like…
test('some executions after the message is removed works as expected', async () => {
render(<SomeComponent />);
const targetElement = getByText('some message');
const isRemovedPromise = waitForElementToBeRemoved(targetElement);
// an action to remove the message
await user.click(getByRole('button', { name: 'remove message' }));
// wait until the message is removed
await isRemovedPromise;
// It is explicit that the following code is executed after the "some message" is removed
doSomething();
})
passable? (Some care needed to handle the dangling promise with a subtle change if being strict with resource cleanup and for if the click throws)
from dom-testing-library.
The problem with your suggestion would be that it would require everyone to make an additional manual assertion like you have at the start of the test, to ensure the element exists before proceeding.
Otherwise if changed as suggested, simply doing
waitForElementToBeRemoved(screen.queryBy...)
Would no longer fail if the element never existed in the first place.
So basically it would be making the API less flexible, just for the sake of avoiding one extra check.
from dom-testing-library.
@cmorten
Thank you for your suggestion! That works on my cases.
from dom-testing-library.
it would be making the API less flexible
I think my suggestion makes the API requiring more effort, but also MORE flexible 😉
So how can we ensure that the element exists at the start of the waitForElementToBeRemoved
?
If we use await waitForElementToBeRemoved(screen.queryBy...)
after any actions to remove a element, we must consider the possibility that the element have already removed at the start of it unless we know it takes much time to complete the removing actions.
We should consider more carefully about the timing of asynchronous processing.
from dom-testing-library.
Related Issues (20)
- 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
- `screen` incompatible with document.body.replaceWith() HOT 2
- `alt` attribute can't be empty HOT 1
- Highlight non-breaking whitespace in getByRole failure message
- Conflict with symfony's live components HOT 3
- [attribute selector]:has(+ el) pseudo-class selector with emotionStyled reported as syntax error HOT 4
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.