-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test that the component appears only after scrolling down is not possible? #671
Comments
If you're running your tests in jsdom that's the issue. JSDOM doesn't support layout. You'll need to write these tests in a real browser to test this. Try Cypress, TestCafe, or Puppeteer. There are Testing Library implementations for all three of these. Good luck! |
Ok so Thanks a lot for the super quick response! |
To be clear: the issue you're having is with jsdom's limitations... Not React Testing Library. If you run your tests in a real browser then it will work just fine. React Testing Library works in a real browser as well as jest/jsdom. So, React Testing Library is absolutely meant for these kinds of use cases. It's jsdom that's not meant for these kind of use cases. |
Thanks for clearing that up :) |
@kentcdodds Hi! Now I am trying to use react-testing-library with jest-puppeteer env and as a result I have the next error: The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/en/configuration#testenvironment-string. So, do you have any example how to replace jsdom in react-testing-library? Thank you |
Hi @alexVasylenko, can you please clarify what you mean? If you meant something else, please elaborate cause I'm not sure I got what you mean.. thanks! |
Hi Kent, thanks for all the hard work!
I can't seem to verify with tests that my component is appearing after the user scrolls down past a certain point. In this particular case, the
<GoToTopButton>
shows itself only after the element with idgoToFragmentId
is above the viewport.But that doesn't seem to happen for some reason. I've included some sample code.
await fireEvent.scroll(window, { target: { scrollY: 300 } });
200ms
(since the 'scroll' event listener is debounced)200ms
of the scroll event.console.log(window.scrollY);
Outputs:300
, which is correctconsole.log(getByText('Top of the Page - Scroll Down ⬇️').getBoundingClientRect().bottom);
Outputs0
which is incorrect!I'm not sure why is this so, the text is long enough to take a couple of pages of normal screen height.
Thanks for looking into this!
Dusan D.
The text was updated successfully, but these errors were encountered: