React-redux: Upgrade from 7.1.0 to 7.1.1 broke karma/mocha testcases with ReactTestUtils.renderIntoDocument

Created on 27 Aug 2019  路  5Comments  路  Source: reduxjs/react-redux

Do you want to request a _feature_ or report a _bug_?

bug

What is the current behavior?

Starting from 7.1.1 result of ReactTestUtils.renderIntoDocument( <Provider> ) is null

import { createStore } from 'redux';
import { Provider } from 'react-redux';
import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';

describe( 'react-redux', () => {

  it( 'can render Provider with ReactTestUtils', () => {
    const fakeReducers = ( state = {} ) => state;
    const fakeStore = createStore( fakeReducers );

    const rendered = ReactTestUtils.renderIntoDocument( <Provider store={fakeStore}>
      <div>Hello, World!</div>
    </Provider> );
    if ( !rendered ) throw new Error( 'Unable to render, ' +
      'result of renderIntoDocument() is ' + rendered );
  } );

} );

What is the expected behavior?

Expected result (works for 7.1.0): test passed
Current result (7.1.1): Unable to render, result of renderIntoDocument() is null

Which versions of React, ReactDOM/React Native, Redux, and React Redux are you using? Which browser and OS are affected by this issue? Did this work in previous versions of React Redux?

    "jsdom": "^15.1.1",
    "karma": "^4.2.0",
    "karma-chrome-launcher": "^3.1.0",
    "karma-jsdom-launcher": "^7.1.1",
    "karma-mocha": "^1.3.0",
    "karma-mocha-reporter": "^2.2.5",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^4.0.2",
...
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-redux": "^7.1.1",
    "redux": "^4.0.4",

Most helpful comment

Is this because Provider is now a functional component?

I think the discussion in https://github.com/facebook/react/issues/15370 is relevant.

All 5 comments

I'm not sure renderIntoDocument is supposed to return anything. Their docs don't mention it: https://reactjs.org/docs/test-utils.html#renderintodocument

I would do as the example in that section shows and create a DOM element explicitly and then use render on it.

Is this because Provider is now a functional component?

I think the discussion in https://github.com/facebook/react/issues/15370 is relevant.

@darsee , thanks for the link. That is exactly what happens.

@timdorr, I agree that not a bug, but such change should not appear in semver patch release, IMHO.

The API hasn't changed, so we haven't broken semver.

I am getting a similar error upon upgrade to 7.1.1 in use with enzyme.

Was this page helpful?
0 / 5 - 0 ratings