scrollIntoView is not a function

See original GitHub issue

I’m running a test using a library (grommet) that uses scrollIntoView on an a tag. jsdom is throwing errors when hitting that line of code. I was able to get it to work by adding window.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.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:47
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

98reactions
enessoylucommented, Dec 26, 2018

@QuantumInformation You can use this for the Jest:

Element.prototype.scrollIntoView = jest.fn();

8reactions
msmetanacommented, Nov 27, 2019

hello, you can use window.HTMLElement.prototype.scrollIntoView = jest.fn()

Read more comments on GitHub >

github_iconTop Results From Across the Web

scrollIntoView() is not a function upon page load?
scrollIntoView is part of the DOM API, not jQuery. You need to run it on an Element, not a jQuery object: $('div#' +...
Read more >
[Solved]-TypeError: scrollIntoView is not a function-Reactjs
If we want to unit test 'scrollIntoView' function in a react application using react testing library then we can mock the function using...
Read more >
jQuery : scrollIntoView() is not a function upon page load?
jQuery : scrollIntoView() is not a function upon page load? [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] jQuery ...
Read more >
Element.scrollIntoView() - Web APIs | MDN
The Element interface's scrollIntoView() method scrolls the element's ancestor containers such that the element on which scrollIntoView() is ...
Read more >
javascript error: cannot read properties of null ... - You.com
Because jsdom does not implement scrollIntoView it will be undefined on elements provided by jsdom . Solution. The recommended approach from this Google...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found