TypeError: scrollIntoView is not a function










0















I am new to react-testing-library / jest and attempting to write a test to see if the navigation of routes (using react-router-dom) is performed correctly. So far I have been following the README and this tutorial on how to use.



One of my components uses scrollIntoView in a local function and this causes the test to fail.



TypeError: this.messagesEnd.scrollIntoView is not a function

45 |
46 | scrollToBottom = () => this.messagesEnd.scrollIntoView( behavior: "smooth" );

49 |
50 |


This is the function in my chatbot component:



componentDidUpdate() 
this.scrollToBottom();


scrollToBottom = () =>
this.messagesEnd.scrollIntoView( behavior: "smooth" );



And this is a sample of the tests that fail:



test('<App> default screen', () => 

const getByTestId, getByText = renderWithRouter(<App />)

expect(getByTestId('index'))

const leftClick = button: 0
fireEvent.click(getByText('View Chatbot'), leftClick) <-- test fails

expect(getByTestId('chatbot'))

)


I have tried to use a mock function, however the error still remains.



This is where this.messageEnd is assigned:



 <div className="chatbot">
<div className="chatbot-messages">
//render messages here
</div>
<div className="chatbot-actions" ref=(el) => this.messagesEnd = el; >
//inputs for message actions here
</div>
</div>


I referenced code from this stack overflow question: How to scroll to bottom in react?



SOLUTION



test('<App> default screen', () => 

window.HTMLElement.prototype.scrollIntoView = function() ;

const getByTestId, getByText = renderWithRouter(<App />)

expect(getByTestId('index'))

const leftClick = button: 0
fireEvent.click(getByText('View Chatbot'), leftClick)

expect(getByTestId('chatbot'))

)









share|improve this question
























  • Can you post where you assign the value of this.messagesEnd?

    – Gpx
    Nov 13 '18 at 7:43











  • Sure thing, I updated the original question.

    – Charklewis
    Nov 13 '18 at 21:27











  • Would it work if you force the casting? (<HTMLElement>this.messagesEnd).scrollIntoView( behavior: "smooth" );

    – Iskandar Reza Razali
    Nov 14 '18 at 0:28















0















I am new to react-testing-library / jest and attempting to write a test to see if the navigation of routes (using react-router-dom) is performed correctly. So far I have been following the README and this tutorial on how to use.



One of my components uses scrollIntoView in a local function and this causes the test to fail.



TypeError: this.messagesEnd.scrollIntoView is not a function

45 |
46 | scrollToBottom = () => this.messagesEnd.scrollIntoView( behavior: "smooth" );

49 |
50 |


This is the function in my chatbot component:



componentDidUpdate() 
this.scrollToBottom();


scrollToBottom = () =>
this.messagesEnd.scrollIntoView( behavior: "smooth" );



And this is a sample of the tests that fail:



test('<App> default screen', () => 

const getByTestId, getByText = renderWithRouter(<App />)

expect(getByTestId('index'))

const leftClick = button: 0
fireEvent.click(getByText('View Chatbot'), leftClick) <-- test fails

expect(getByTestId('chatbot'))

)


I have tried to use a mock function, however the error still remains.



This is where this.messageEnd is assigned:



 <div className="chatbot">
<div className="chatbot-messages">
//render messages here
</div>
<div className="chatbot-actions" ref=(el) => this.messagesEnd = el; >
//inputs for message actions here
</div>
</div>


I referenced code from this stack overflow question: How to scroll to bottom in react?



SOLUTION



test('<App> default screen', () => 

window.HTMLElement.prototype.scrollIntoView = function() ;

const getByTestId, getByText = renderWithRouter(<App />)

expect(getByTestId('index'))

const leftClick = button: 0
fireEvent.click(getByText('View Chatbot'), leftClick)

expect(getByTestId('chatbot'))

)









share|improve this question
























  • Can you post where you assign the value of this.messagesEnd?

    – Gpx
    Nov 13 '18 at 7:43











  • Sure thing, I updated the original question.

    – Charklewis
    Nov 13 '18 at 21:27











  • Would it work if you force the casting? (<HTMLElement>this.messagesEnd).scrollIntoView( behavior: "smooth" );

    – Iskandar Reza Razali
    Nov 14 '18 at 0:28













0












0








0








I am new to react-testing-library / jest and attempting to write a test to see if the navigation of routes (using react-router-dom) is performed correctly. So far I have been following the README and this tutorial on how to use.



One of my components uses scrollIntoView in a local function and this causes the test to fail.



TypeError: this.messagesEnd.scrollIntoView is not a function

45 |
46 | scrollToBottom = () => this.messagesEnd.scrollIntoView( behavior: "smooth" );

49 |
50 |


This is the function in my chatbot component:



componentDidUpdate() 
this.scrollToBottom();


scrollToBottom = () =>
this.messagesEnd.scrollIntoView( behavior: "smooth" );



And this is a sample of the tests that fail:



test('<App> default screen', () => 

const getByTestId, getByText = renderWithRouter(<App />)

expect(getByTestId('index'))

const leftClick = button: 0
fireEvent.click(getByText('View Chatbot'), leftClick) <-- test fails

expect(getByTestId('chatbot'))

)


I have tried to use a mock function, however the error still remains.



This is where this.messageEnd is assigned:



 <div className="chatbot">
<div className="chatbot-messages">
//render messages here
</div>
<div className="chatbot-actions" ref=(el) => this.messagesEnd = el; >
//inputs for message actions here
</div>
</div>


I referenced code from this stack overflow question: How to scroll to bottom in react?



SOLUTION



test('<App> default screen', () => 

window.HTMLElement.prototype.scrollIntoView = function() ;

const getByTestId, getByText = renderWithRouter(<App />)

expect(getByTestId('index'))

const leftClick = button: 0
fireEvent.click(getByText('View Chatbot'), leftClick)

expect(getByTestId('chatbot'))

)









share|improve this question
















I am new to react-testing-library / jest and attempting to write a test to see if the navigation of routes (using react-router-dom) is performed correctly. So far I have been following the README and this tutorial on how to use.



One of my components uses scrollIntoView in a local function and this causes the test to fail.



TypeError: this.messagesEnd.scrollIntoView is not a function

45 |
46 | scrollToBottom = () => this.messagesEnd.scrollIntoView( behavior: "smooth" );

49 |
50 |


This is the function in my chatbot component:



componentDidUpdate() 
this.scrollToBottom();


scrollToBottom = () =>
this.messagesEnd.scrollIntoView( behavior: "smooth" );



And this is a sample of the tests that fail:



test('<App> default screen', () => 

const getByTestId, getByText = renderWithRouter(<App />)

expect(getByTestId('index'))

const leftClick = button: 0
fireEvent.click(getByText('View Chatbot'), leftClick) <-- test fails

expect(getByTestId('chatbot'))

)


I have tried to use a mock function, however the error still remains.



This is where this.messageEnd is assigned:



 <div className="chatbot">
<div className="chatbot-messages">
//render messages here
</div>
<div className="chatbot-actions" ref=(el) => this.messagesEnd = el; >
//inputs for message actions here
</div>
</div>


I referenced code from this stack overflow question: How to scroll to bottom in react?



SOLUTION



test('<App> default screen', () => 

window.HTMLElement.prototype.scrollIntoView = function() ;

const getByTestId, getByText = renderWithRouter(<App />)

expect(getByTestId('index'))

const leftClick = button: 0
fireEvent.click(getByText('View Chatbot'), leftClick)

expect(getByTestId('chatbot'))

)






javascript reactjs react-router jestjs react-testing-library






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 3:06







Charklewis

















asked Nov 12 '18 at 22:46









CharklewisCharklewis

5318




5318












  • Can you post where you assign the value of this.messagesEnd?

    – Gpx
    Nov 13 '18 at 7:43











  • Sure thing, I updated the original question.

    – Charklewis
    Nov 13 '18 at 21:27











  • Would it work if you force the casting? (<HTMLElement>this.messagesEnd).scrollIntoView( behavior: "smooth" );

    – Iskandar Reza Razali
    Nov 14 '18 at 0:28

















  • Can you post where you assign the value of this.messagesEnd?

    – Gpx
    Nov 13 '18 at 7:43











  • Sure thing, I updated the original question.

    – Charklewis
    Nov 13 '18 at 21:27











  • Would it work if you force the casting? (<HTMLElement>this.messagesEnd).scrollIntoView( behavior: "smooth" );

    – Iskandar Reza Razali
    Nov 14 '18 at 0:28
















Can you post where you assign the value of this.messagesEnd?

– Gpx
Nov 13 '18 at 7:43





Can you post where you assign the value of this.messagesEnd?

– Gpx
Nov 13 '18 at 7:43













Sure thing, I updated the original question.

– Charklewis
Nov 13 '18 at 21:27





Sure thing, I updated the original question.

– Charklewis
Nov 13 '18 at 21:27













Would it work if you force the casting? (<HTMLElement>this.messagesEnd).scrollIntoView( behavior: "smooth" );

– Iskandar Reza Razali
Nov 14 '18 at 0:28





Would it work if you force the casting? (<HTMLElement>this.messagesEnd).scrollIntoView( behavior: "smooth" );

– Iskandar Reza Razali
Nov 14 '18 at 0:28












1 Answer
1






active

oldest

votes


















0














scrollIntoView is not implemented in jsdom. Here's the issue: link.



You might get it working by manually adding it:



window.HTMLElement.prototype.scrollIntoView = function() ;





share|improve this answer


















  • 1





    Thank you @Gpx, this worked. I have added the solution to the original post.

    – Charklewis
    Nov 16 '18 at 3:05










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271193%2ftypeerror-scrollintoview-is-not-a-function%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














scrollIntoView is not implemented in jsdom. Here's the issue: link.



You might get it working by manually adding it:



window.HTMLElement.prototype.scrollIntoView = function() ;





share|improve this answer


















  • 1





    Thank you @Gpx, this worked. I have added the solution to the original post.

    – Charklewis
    Nov 16 '18 at 3:05















0














scrollIntoView is not implemented in jsdom. Here's the issue: link.



You might get it working by manually adding it:



window.HTMLElement.prototype.scrollIntoView = function() ;





share|improve this answer


















  • 1





    Thank you @Gpx, this worked. I have added the solution to the original post.

    – Charklewis
    Nov 16 '18 at 3:05













0












0








0







scrollIntoView is not implemented in jsdom. Here's the issue: link.



You might get it working by manually adding it:



window.HTMLElement.prototype.scrollIntoView = function() ;





share|improve this answer













scrollIntoView is not implemented in jsdom. Here's the issue: link.



You might get it working by manually adding it:



window.HTMLElement.prototype.scrollIntoView = function() ;






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 7:16









GpxGpx

1,60821524




1,60821524







  • 1





    Thank you @Gpx, this worked. I have added the solution to the original post.

    – Charklewis
    Nov 16 '18 at 3:05












  • 1





    Thank you @Gpx, this worked. I have added the solution to the original post.

    – Charklewis
    Nov 16 '18 at 3:05







1




1





Thank you @Gpx, this worked. I have added the solution to the original post.

– Charklewis
Nov 16 '18 at 3:05





Thank you @Gpx, this worked. I have added the solution to the original post.

– Charklewis
Nov 16 '18 at 3:05

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271193%2ftypeerror-scrollintoview-is-not-a-function%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20