Skip to content

Latest commit

 

History

History
executable file
·
44 lines (27 loc) · 1.03 KB

README.md

File metadata and controls

executable file
·
44 lines (27 loc) · 1.03 KB

This project was bootstrapped with Create React App.

Testing React 16 Portals with enzyme

This is a repo with an example of a working modal, using React 16 Portals.

This is the solution for the question and answer that I posted on stackoverflow

Running the project

Install dependencies

yarn|npm install

Start the project

yarn|npm start

Run the tests

yarn|npm test

Testing portals

So basically the idea is that for us to test portals we need to modify our jsdom so when we use enzyme to mount our components, we have the desired div. To modify the default jsdom html all we need to do before running our tests is this:

const modalRoot = global.document.createElement('div');
modalRoot.setAttribute('id', 'modal-root');
const body = global.document.querySelector('body');
body.appendChild(modalRoot);

the code and the tests are self explanatory.