React-modal: Create testing examples

Created on 28 Dec 2016  路  5Comments  路  Source: reactjs/react-modal

Because testing seems to be less understood than many other things we should create a few examples of testing for people to see.

I think the biggest thing people want to test is opening the modal and asserting various facts about the contents of the modal.

We should create examples for the following:

  • [ ] Mocha

    • [ ] Enzyme

    • [ ] React TestUtils

  • [ ] Jest
documentation

Most helpful comment

Please provide some examples on how to access the portal using enzyme

All 5 comments

Please provide some examples on how to access the portal using enzyme

"jest" involves snapshot example with react-test-renderer ?

if this helps anyone, I had to add a dummy app element to get around the App element is not defined error in Jest:

  let app = document.createElement('div');
  app.id = 'app';

  document
    .getElementsByTagName('body')
    .item(0)
    .appendChild(app);

  Modal.setAppElement('#app');

@aziz I ended up piping some innerHTML to jest snapshots, but I did find this helpful:

http://remarkablemark.org/blog/2017/05/17/testing-react-modal/

Was this page helpful?
0 / 5 - 0 ratings