-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: parentInstance.children.indexOf is not a function #553
Comments
@vietnogi I'm marking this as duplicated since we already have some issues related to testing...Thank you! |
@diasbruno Awesome to see you managing issues! But ehm... could you perhaps include the duplicates in this ticket? 😅 Update: This issue is #1 in the google search results, that's why. |
@RWOverdijk gee, sorry. I'm trying to keep everything organized, respond issue and stuff, but, you know, time is the problem. Thanks for the heads up and everyone is welcome to contribute to this repo either fixing bugs or helping with management. 👍 |
...also, this is not an duplicated issue. Perhaps I've overlooked. I'll reopen this. |
@diasbruno No problem. I know how time consuming it is. Thanks for reopening! |
I had the exact same issue, got it working by using enzyme-to-json instead of react-test-renderer
|
Something else that works is mocking the Portal in the top of the test file like this: jest.mock('rc-util/lib/Portal') Obviously you'll need to install the |
Wanted to reference some sweet news I saw in another similar issue: Sounds like the next React release will have a fix for this 🎉 |
This is caused by facebook/react#11565. There is a workaround, which is mocking/overwriting |
Mocking/overwriting I'm going to open a PR to put that logic into a method. |
Fixes reactjs#553 - PR reactjs#701 * Allow ReactDOM.createPortal to be mocked in tests (9cd0891) * add testability tests (6a67946) * linting (f29e7b0) * more linting (5992f97)
thanks, that works! |
I'm facing the same problem. Here I'm using snapshot tests with import renderer from 'react-test-renderer';
it('should match snapshot', () => {
const tree = renderer
.create(<ChangeTitleModal visible oldTitle="Old title" onChange={jest.fn()} onCancel={jest.fn()} />)
.toJSON();
expect(tree).toMatchSnapshot();
}); Does anyone can solve this? |
I'm set up simply like this:
and things break with |
add useState to service; note: test Modal snapshot error: parentInstance.children.indexOf is not a function refer to: reactjs/react-modal#553 https://medium.com/@amanverma.dev/mocking-create-portal-to-utilize-react-test-renderer-in-writing-snapshot-uts-c49773c88acd this is react-test-renderer's bug that the Modal use createPortal and cause the error! so not test Modal snapshot!
Summary:
Getting
TypeError: parentInstance.children.indexOf is not a function
error when using react-test-renderer to write tests.Steps to reproduce:
Expected behavior:
No error
Link to example of issue:
enzymejs/enzyme#1150
Additional notes:
The text was updated successfully, but these errors were encountered: