I would like to have 100% coverage of my project.

To do this, I need to check the index.js file, which is very simple:
index.js
import React from 'react'; import ReactDOM from 'react-dom'; ReactDOM.render(<App/>, document.getElementById('root'));
I can not find how to check this. When creating a function, for example:
index.js
const index = (div) => { ReactDOM.render(<App />, div || document.getElementById('root')); };
and then check it out:
index.test.js
it('renders without crashing', () => { const div = document.createElement('div'); index(div); });
I get an error when importing index : Invariant violation: _registerComponent (...): The target container is not a DOM element.
PS:
Please note that I already have the following test that works perfectly:
App.test.jsx
it('renders without crashing', () => { const div = document.createElement('div'); ReactDOM.render(<App/>, div); });
reactjs react-jsx jestjs
Thomas Sauvajon
source share