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:
TypeError: Cannot read property 'parentNode' of undefined
at node_modules/piwik-react-router/index.js:171:6
at PiwikTracker (node_modules/piwik-react-router/index.js:173:4)
at Object.<anonymous> (src/components/App.js:14:46)
at Object.<anonymous> (src/components/App.test.js:3:12)
at Generator.next (<anonymous>)
at new Promise (<anonymous>)
at handle (node_modules/worker-farm/lib/child/index.js:44:8)
at process.<anonymous> (node_modules/worker-farm/lib/child/index.js:51:3)
at emitTwo (events.js:126:13)
at process.emit (events.js:214:7)
at emit (internal/child_process.js:772:12)
at _combinedTickCallback (internal/process/next_tick.js:141:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
I am using jest to run my tests, and I tried to run the default test found here
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
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. The s is a script element that it just created and got like this:
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
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?