Enzyme: Support react-dom/test-utils

Created on 8 Apr 2017  ·  33Comments  ·  Source: enzymejs/enzyme

Today's announcement moves react-addons-test-utils to react-dom/test-utils. I'm not sure I understand all the intricacies of the test utils requirements from enzyme, but I expect that something may be able to be done about the requirement for react-addons-test-utils. Any chance this could be revisited?

Most helpful comment

Workaround for me was to install react-test-renderer as dev dependency and errors was gone

All 33 comments

Actually, it looks like more than just a convenience thing, I'm now getting these warnings in any test that uses enzyme:

 console.error node_modules/fbjs/lib/warning.js:36
      Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.

So I think we'll want to get on this ASAP. I'm looking into it now. Any tips are appreciated because I don't know this codebase at all...

We definitely need to fix this ASAP; React doesn't consider warnings semver-major, but any responsible developer makes console warnings and errors fail their tests, so this will affect many.

I think I've got something. PR coming soon. Fun story, I've found something else too with prop-types. Making another issue :)

Actually, I think I'll just tag this all as v15.5 fixes and do it in one.

PR open here: #876

Just chiming in here because I started seeing the errors today, does this one have to do with React moving createClass to it's own package as well?

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

Yes, my pull request fixes that in enzyme. Though a bunch of other libs will need to update as well...

So I need to upgrade to react 15.5 to clear this message?

So I need to upgrade to react 15.5 to clear this message?

No. If you upgrade to react 15.5 then you will start seeing this message. The only way to get the message to go away is to remove _all_ uses of React.propTypes and React.createClass from your codebase (including your dependencies). See the blogpost for more info.

Has this been released yet? I've taken all the above steps and installed the latest version (2.8.2) and still see Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning. in the console when running tests.

@planttheidea yes, it's released. If any of your code, or any dependency in your entire tree references a deprecated property, you'll see the warning. It's coming from React, not from enzyme.

I'm also seeing this with Enzyme 2.8.2, I changed fbjs' printWarning from console.error to console.trace to see where it was coming from:

console.error console.js:89
  Trace: Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.
      at printWarning (/Users/jlewis/git/my-project/node_modules/fbjs/lib/warning.js:36:17)
      at warning (/Users/jlewis/git/my-project/node_modules/fbjs/lib/warning.js:60:22)
      at Object.<anonymous> (/Users/jlewis/git/my-project/node_modules/react-addons-test-utils/index.js:17:1)
      at Runtime._execModule (/Users/jlewis/git/my-project/node_modules/jest-runtime/build/index.js:447:13)
      at Runtime.requireModule (/Users/jlewis/git/my-project/node_modules/jest-runtime/build/index.js:295:14)
      at Runtime.requireModuleOrMock (/Users/jlewis/git/my-project/node_modules/jest-runtime/build/index.js:365:19)
      at /Users/jlewis/git/my-project/node_modules/enzyme/build/react-compat.js:143:21
      at Object.<anonymous> (/Users/jlewis/git/my-project/node_modules/enzyme/build/react-compat.js:214:5)
      at Runtime._execModule (/Users/jlewis/git/my-project/node_modules/jest-runtime/build/index.js:447:13)
      at Runtime.requireModule (/Users/jlewis/git/my-project/node_modules/jest-runtime/build/index.js:295:14)

@rhinoceraptor You are probably missing react-test-renderer. The readme has been updated and mentions that it is now a required devDependency.

Detection for React 15.5 uses a try-catch block which swallows the actual error (Cannot find module 'react-test-renderer/shallow').

I'm using create react apps, with react-scripts. When I run enzyme with jest, I still get this output ... am I missing something?

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

CRA may have been updated already, but you need to have react-test-renderer in your node_modules. You can run: npm i --save-dev react-test-renderer.

I've found something else too with prop-types. Making another issue :).

@kentcdodds can you explain more about your comment?

All of my tests that are using a library on [email protected] and [email protected] are failing. It seems that the prop-types package is not actually being loaded before the tests are run.

@juliacochran it's not that you need to load prop-types, it's that nothing can be accessing React.PropTypes, ever - they instead need to import/require from 'prop-types' directly.

Workaround for me was to install react-test-renderer as dev dependency and errors was gone

For me, I remove jest.runAllTicks and jest.runAllTimers calls. and errors was gone.

I'm using [email protected], I have also installed [email protected][email protected], the warning persists, what else should I do?

@kimjuny all react-* versions should match; try v15.4.2 of react-addons-test-utils also.

@ljharb that fixed my problem 👌

@OscarBarrett Thanks, solved for me as well.

Ensuring all version numbers match is what fixed it for me

although react-addons-test-utils is deprecated for version 15.5.4

From https://www.npmjs.com/package/react-addons-test-utils:

15.5.1 is the latest of 55 releases

When trying to NPM install v15.5.2 exactly I get:

In most cases you or one of your dependencies are requesting a package version that doesn't exist.

How are you guys getting 15.5.2 installed?

I can confirm @jetpack3331 suggestion does the trick.

good~

I've just started using enzyme and discovered that the installation instructions from the enzyme docs does not contain the heads up on missing the react-test-renderer dependency. Navigating to the project's README isn't too hard but I thought it could be a nuisance to some people. (I apologize if the docs I was referring to was wrong)

Note, you should follow the installation instructions for your version of React, and ensure, if you're installing react-dom, the version matches that of React. https://github.com/airbnb/enzyme/tree/master/docs/installation

I'm not sure why I'm getting this warning since I haven't found any references in my project:

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

@nemanjacosovic make sure you’re using enzyme 3.2, the right version of react and of the right enzyme adapter.

all you have to do is remove react-addons-test-utils and include react-test-renderer as dev dependency

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ivanbtrujillo picture ivanbtrujillo  ·  3Comments

abe903 picture abe903  ·  3Comments

heikkimu picture heikkimu  ·  3Comments

nelsonchen90 picture nelsonchen90  ·  3Comments

blainekasten picture blainekasten  ·  3Comments