Skip to content
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

Support react-dom/test-utils #875

Closed
kentcdodds opened this issue Apr 7, 2017 · 33 comments
Closed

Support react-dom/test-utils #875

kentcdodds opened this issue Apr 7, 2017 · 33 comments

Comments

@kentcdodds
Copy link
Contributor

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?

@kentcdodds
Copy link
Contributor Author

kentcdodds commented Apr 7, 2017

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...

@ljharb
Copy link
Member

ljharb commented Apr 7, 2017

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.

@kentcdodds
Copy link
Contributor Author

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

@kentcdodds
Copy link
Contributor Author

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

kentcdodds pushed a commit to kentcdodds/enzyme that referenced this issue Apr 7, 2017
A few deprecation warnings were added in React@15.5. This supports the
new APIs that React recommends.

Closes enzymejs#875
@kentcdodds
Copy link
Contributor Author

PR open here: #876

@thecodegoddess
Copy link

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.

@kentcdodds
Copy link
Contributor Author

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

ljharb pushed a commit to kentcdodds/enzyme that referenced this issue Apr 9, 2017
A few deprecation warnings were added in React@15.5. This supports the
new APIs that React recommends.

Closes enzymejs#875
ljharb pushed a commit to kentcdodds/enzyme that referenced this issue Apr 10, 2017
A few deprecation warnings were added in React@15.5. This supports the
new APIs that React recommends.

Closes enzymejs#875
nfcampos pushed a commit to kentcdodds/enzyme that referenced this issue Apr 10, 2017
A few deprecation warnings were added in React@15.5. This supports the
new APIs that React recommends.

Closes enzymejs#875
nfcampos pushed a commit to kentcdodds/enzyme that referenced this issue Apr 10, 2017
A few deprecation warnings were added in React@15.5. This supports the
new APIs that React recommends.

Closes enzymejs#875
ljharb pushed a commit to kentcdodds/enzyme that referenced this issue Apr 12, 2017
A few deprecation warnings were added in React@15.5. This supports the
new APIs that React recommends.

Closes enzymejs#875
ljharb pushed a commit to kentcdodds/enzyme that referenced this issue Apr 12, 2017
A few deprecation warnings were added in React@15.5. This supports the
new APIs that React recommends.

Closes enzymejs#875
@mikepc
Copy link

mikepc commented Apr 12, 2017

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

@kentcdodds
Copy link
Contributor Author

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.

@OscarBarrett
Copy link

@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').

@danieldram
Copy link

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.

@rhinoceraptor
Copy link

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.

@juliacochran
Copy link

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 react@15.5.4 and prop-types@15.5.8 are failing. It seems that the prop-types package is not actually being loaded before the tests are run.

@ljharb
Copy link
Member

ljharb commented Apr 22, 2017

@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.

@jetpack3331
Copy link

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

@Ridermansb
Copy link

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

@kimjuny
Copy link

kimjuny commented May 7, 2017

I'm using react@15.4.2, I have also installed react-test-renderer@15.4.2、react-addons-test-utils@15.5.1, the warning persists, what else should I do?

@ljharb
Copy link
Member

ljharb commented May 7, 2017

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

@kimjuny
Copy link

kimjuny commented May 8, 2017

@ljharb that fixed my problem 👌

@Ballpin
Copy link

Ballpin commented May 10, 2017

@OscarBarrett Thanks, solved for me as well.

@WickyNilliams
Copy link

Ensuring all version numbers match is what fixed it for me

@damiangreen
Copy link

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

@davidworkman9
Copy link

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?

@DZuz14
Copy link

DZuz14 commented Jun 25, 2017

I can confirm @jetpack3331 suggestion does the trick.

@BingoBingo
Copy link

good~

@ktnyt
Copy link

ktnyt commented Sep 13, 2017

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)

@archy-bold
Copy link

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

@nemanjacosovic
Copy link

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.

@ljharb
Copy link
Member

ljharb commented Nov 30, 2017

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

@thiagoh
Copy link

thiagoh commented Dec 23, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests