-
Notifications
You must be signed in to change notification settings - Fork 22
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
TypeError: Cannot read property 'parentNode' of undefined #48
Comments
i had a similar issue while i was writing the tests and fixed it quiet dirty: https://github.com/joernroeder/piwik-react-router/blob/master/test/client.tests.js#L13 i didn't find some time to look into this so please let me know if you find a better solution for this. |
So, the "problematic" piece of code (that creates the problem in tests) is this bit here:
If I understand correctly, this bit seems to add a I refactored this code to look like this:
This code does the same thing. It adds a This solves the issue, because a Everything else works the same just fine. If you test this and it is ok with you as well, and you plan to implement this in your library, could I make a pull/merge request? |
@mandarini thanks for looking into this. yes |
You are right. However, I think that the piwik injection |
yes. it also decides to append itself to the |
had the same problem, when testing with jest + jsdom. So I forked the package and applied @mandarini's suggestion: Maybe you can pull her commit: |
Ok, I was to quick in my earlier comment, that change only works if there actually is a script tag on the body, but breaks when all scripts are in the head. So I just added a check if the regular way works (finding the parent node - either head or body) and simply append the script node if it fails. Now my test suite works, as well as the packages' test suite.
update: I changed the test suite to only add an empty script tag, when the test explicitly requires it. |
@fargerio How did you add an empty script tag, when the test explicitly requires it? Can you provide some examples? |
@vinuganesan like this, just using vanilla js at the beginning of each test that requires an empty script tag to be present: // add script tag for piwik initialization to find
let emptyScriptTag = document.createElement('script');
document.getElementsByTagName('body')[0].appendChild(emptyScriptTag); This is the corresponding commit: 73ea7f6 |
@fargerio Thanks. Now working fine |
I am creating a ReactJS application and I am using piwik-react-router. Everything is running ok. However, when I run a simple test on my App.js, I get the following error:
I am using jest to run my tests, and I tried to run the default test found here
I import piwik in my App.js like this:
import PiwikReactRouter from 'piwik-react-router';
The error in piwik-react-router/index.js is on line 171 when it is trying to access
s.parentNode
. Thes
is a script element that it just created and got like this:I have set my jest environment to be jsdom, however, it seems that it still cannot find the script.
Is this a known issue? What can I do about this?
The text was updated successfully, but these errors were encountered: