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
scrollIntoView is not a function #1695
Comments
Yeah this might be worth adding a not-implemented-warning stub for. We can't really implemented it since we don't do layout. |
Any movement on this? Trying to use in a Jest test, I'm trying to mount a component that calls scrollIntoView on an element, and the test always fails with
|
@quantuminformation You can use this for the Jest:
|
I see this fix everywhere, but were are you importing Element from? I get 'Element is not defined' I am using enzyme with chai. |
You need Element in your tsconfig libs: ie |
@qmg-JamesT It is the global element class where the other elements are inherited scrollIntoView method from. |
Hi, is there any update on this without using jest? |
hello, you can use window.HTMLElement.prototype.scrollIntoView = jest.fn() |
I need the same for Element.prototype.scroll = jest.fn() @enessoylu and @MSmetana where do you recommend putting When using CRA there is a setupTest.ts, seems to work but idk import '@testing-library/jest-dom/extend-expect'
Element.prototype.scroll = jest.fn() |
For |
For me it was enough to set:
once into setupJest.ts |
This also seems to be the case with |
Thanks! it worked. |
try this one.. |
How can I mock value for srcollIntoView? I'm using enzyme shallow / jest. I'm getting "TypeError: Cannot read property 'scrollIntoView' of null. " Any advice would be helpful, I don't need to test anything regarding to scrollIntoView, I just need to mock some values, because my test failing and can not pass because scrollIntoView is null. Thanks for your time! |
Anyone have an idea why it happens? |
Thank you it works! |
Fix JSDOM is not working with `scrollIntoView` as a bug in JSDOM used for testing creates a DOM environment in memory so that the test can run against it. Unfortunately, that environment does not work well with `scrollIntoView`, used for the React Select. Ref: jsdom/jsdom#1695 (comment)
Fix JSDOM is not working with `scrollIntoView` as a bug in JSDOM used for testing creates a DOM environment in memory so that the test can run against it. Unfortunately, that environment does not work well with `scrollIntoView`, used for the React Select. Ref: jsdom/jsdom#1695 (comment)
Why not add the not-implemented-warning stub as suggested in the second comment? Is there a reason why it has been done for jsdom/lib/jsdom/browser/Window.js Line 931 in 65ef06f
|
It would be nice to have a proper way to restore it after all tests were run but I guess that if we don't have it implemented in jsdom it doesn't care very much. |
I'm running a test using a library (
grommet
) that usesscrollIntoView
on ana
tag.jsdom
is throwing errors when hitting that line of code. I was able to get it to work by addingwindow.HTMLElement.prototype.scrollIntoView = function() {};
in my testHelper file to setup the tests, but I thought I'd report it to see if it's something you want to fix.The text was updated successfully, but these errors were encountered: