Comments (2)
Hi @hyalen, thanks for opening this.
It might be confusing, but the two assertions you're presenting are not equivalent.
expect(await screen.findByText("The answer is 42")).toBeVisible();
This assertion awaits to get an element (using findBy
), once the element is in the DOM, it resolves and the assertion is made.
await waitFor(() =>
expect(screen.getByText("The answer is 42")).toBeVisible()
);
This assertion waits for the expect to be truthy until the timeout passes. There's a slight difference between the two.
This is the desired behavior so I'm resolving this. If you have any further questions or you think I'm wrong here, feel free to comment & re-open.
Thanks!
from react-testing-library.
For those who might want a more detailed explanation: https://codsen.com/articles/waitfor-getby-vs-findby
from react-testing-library.
Related Issues (20)
- When `container` is `document`, cleanup steps fails with "TypeError: Cannot read properties of null (reading 'removeChild')" HOT 3
- `rerender` does not reset state HOT 6
- Unexpected token 'export' error when running Jest tests with React Native Testing Library HOT 1
- Error test Component with setTimeout and vitest
- Do not want to install react & react-dom dependency in node_modules HOT 1
- Warning: The current testing environment is not configured to support act(...) HOT 5
- RTL + Vitest issue with patching asyncWrapper/eventWrapper (with act()) for userEvent APIs
- React-Aria Component Combobox is not Fully rendering in Consuming Application Tests HOT 1
- `hydrate` option does not work in `renderHook` HOT 3
- Module '"@testing-library/react"' has no exported member 'screen'. HOT 7
- Tests using `render` sigificantly slow down in React 19 HOT 7
- wrapper context is not shared with `renderHook`
- Args mapping does not work on composed story from Storybook after Storybook update from 7 to 8 HOT 3
- Test works in isolation but fails alongside other RTL-based tests HOT 4
- Having `afterEach(cleanup)` in the test setup file breaks exported `screen` module on Bun test HOT 2
- Ant Design Typography component doesn't fire onEllipsis event HOT 1
- renderHook support for multiple parameters
- byText not finding element HOT 1
- Can not find createPortal from React DOM
- dispatching of events from rendered components
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 react-testing-library.