ReactTestUtils has been moved

前端 未结 4 1272
南笙
南笙 2020-12-28 17:20

I\'m starting learning React and while I was doing some tests i noticed two warning messages:

Warning: ReactTestUtils has been moved to react-dom/test-ut

相关标签:
4条回答
  • 2020-12-28 17:26

    If you are using React 0.14 or React <15.5, in addition to enzyme, you will have to ensure that you also have the following npm modules installed if they were not already:

    npm i --save-dev react-addons-test-utils react-dom
    

    If you are using React >=15.5, in addition to enzyme, you will have to ensure that you also have the following npm modules installed if they were not already:

    npm i --save-dev react-test-renderer react-dom
    
    0 讨论(0)
  • 2020-12-28 17:33

    I think it's coming from using the shallow render function from enzyme, which has not been updated for v15.5 yet (there is a pull request for it though).

    You can try to use one of the other render function (render or mount), but this will change the semantics of your test (and may or may not still produce the warning).

    Your other option is to not use enzyme and use react-test-renderer/shallow yourself, but the enzyme API is quite nice for testing components.

    My advice is to wait for the version of enzyme and just live with the warning for now.

    0 讨论(0)
  • 2020-12-28 17:38

    Update August of 2017

    If you install react-test-renderer it will work but all react-* versions should match:

    e.g.
    react@15.4.2
    react-test-renderer@15.4.2
    react-dom@15.4.2
    react-addons-test-utils@15.4.2

    In my environment, only this config worked!

    0 讨论(0)
  • 2020-12-28 17:51

    I was still receiving the following warning after trying steps listed above.

    Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.

    Updating the path in \node_modules\react-addons-test-utils\index.js solved this for me.

    Old:

    lowPriorityWarning(
      false,
      'ReactTestUtils has been moved to react-dom/test-utils. ' +
        'Update references to remove this warning.'
    );
    
    module.exports = require('react-dom/lib/ReactTestUtils');
    

    New:

    lowPriorityWarning(
      false,
      'ReactTestUtils has been moved to react-dom/test-utils. ' +
        'Update references to remove this warning.'
    );
    
    module.exports = require('react-dom/test-utils');
    
    0 讨论(0)
提交回复
热议问题