Semantic-ui-react: Cannot test the Modal with react-testing-library and jsdom

Created on 4 Jun 2020  路  3Comments  路  Source: Semantic-Org/Semantic-UI-React

Bug Report

Steps

  1. Open https://codesandbox.io/s/semantic-ui-react-8etbr?file=/index.test.js
  2. Select the index.test.js file on the left sidebar
  3. Select the Tests tab on the right and press the play all button

Expected Result

The resulting HTML printed in the Console section at the bottom of the Tests tab contains the contents of the Modal

Actual Result

In the Console section at the bottom of the Tests tab an empty string is displayed

Version

0.88.2

Testcase

https://codesandbox.io/s/semantic-ui-react-8etbr?file=/index.test.js

question

All 3 comments

馃憢 Thanks for opening your first issue here! If you're reporting a 馃悶 bug, please make sure you've completed all the fields in the issue template so we can best help.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

It's not an of Modal component itself.

Modal uses ReactDOM.createPortal() to render its content to a document.body and it seems that there are issues in react-testing-library (https://github.com/testing-library/react-testing-library/issues/62). I checked the issue at it seems that there is no resolution for this case.

At least I check and selectors like getByText() work (https://codesandbox.io/s/semantic-ui-react-0oume?file=/index.test.js) as expected.

Please let us know if you will find a proper solution.

The solution of adding {container: document.body } as a render option worked for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ctesias picture Ctesias  路  3Comments

GautierT picture GautierT  路  3Comments

AlvMF1 picture AlvMF1  路  3Comments

dilizarov picture dilizarov  路  3Comments

laukaichung picture laukaichung  路  3Comments