React-google-login: Component crashes in Jest test

Created on 24 Nov 2017  路  3Comments  路  Source: anthonyjgrove/react-google-login

I have a typescript react app that's using this component, and have a component test for my login component, which is composed of the react-google-login component.

When I run the test (just to see if the component will render) I get the following error:

TypeError: Cannot read property 'parentNode' of undefined.

Most helpful comment

Could mock a script tag to avoid this problem.

const head = document.getElementsByTagName('head')[0]
head.appendChild(document.createElement('script'))

All 3 comments

This seems to be caused by some logic that is intended to insert the Google login script tag before any existing tags in the DOM. If no script tags exist, parentNode is referenced on the zeroth item which is undefined.

I'm not sure of the original intent of this check so I left it and handled this edge case. If the logic is no longer needed I will remove it completely in my PR @anthonyjgrove . Thanks!

PR here:
https://github.com/anthonyjgrove/react-google-login/pull/143

Could mock a script tag to avoid this problem.

const head = document.getElementsByTagName('head')[0]
head.appendChild(document.createElement('script'))

should be fixed now

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Praneetha-CK picture Praneetha-CK  路  3Comments

scandinaro picture scandinaro  路  5Comments

anthonyjgrove picture anthonyjgrove  路  8Comments

emwee picture emwee  路  4Comments

tameem92 picture tameem92  路  3Comments