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

Unexpected warnings generated during npm test when using enzyme. #1951

Closed
csalvato opened this issue Apr 9, 2017 · 3 comments
Closed

Unexpected warnings generated during npm test when using enzyme. #1951

csalvato opened this issue Apr 9, 2017 · 3 comments

Comments

@csalvato
Copy link

csalvato commented Apr 9, 2017

Can you reproduce the problem with latest npm?

Yup!

Description

When running npm test and basic smoke tests using airbnb/enzyme, I get errors about ReactTest Utils and Shallow rendering.

This code:

import React from 'react'
import { shallow } from 'enzyme'
import App from './App'

it('renders without crashing', () => {
  const div = document.createElement('div');
  shallow(<App />)
});

Generates these warnings:

screen shot 2017-04-08 at 8 06 27 pm

  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.

  console.error node_modules/fbjs/lib/warning.js:36
    Warning: Shallow renderer has been moved to react-test-renderer/shallow. Update references to remove this warning.

This does not happen when I create a smoke test without enzyme:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
  const div = document.createElement('div');
  ReactDOM.render(<App />, div);
});

screen shot 2017-04-08 at 8 07 28 pm

And, because it's probably necessary to track down the problems with this issue, here's my package.json:

{
  "name": "cra-warnings-using-enzyme",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^15.5.3",
    "react-dom": "^15.5.3"
  },
  "devDependencies": {
    "enzyme": "^2.8.0",
    "react-addons-test-utils": "^15.5.0",
    "react-scripts": "0.9.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

I'd like to use enzyme, because I think it's the bee's knees 🐝 (because obviously makes mounting and shallow rendering components really easy).

I want to eliminate warnings, because to me those are as bad as errors and I don't want to ignore them (or potentially ignore other warnings because I go warning-blind).

Expected behavior

I expect that this code will not generate warnings:

import React from 'react'
import { shallow } from 'enzyme'
import App from './App'

it('renders without crashing', () => {
  const div = document.createElement('div');
  shallow(<App />)
});

Actual behavior

The above code generates warnings outlined in the description.

Environment

npm ls react-scripts

react-scripts@0.9.5

node -v:

v6.10.0

npm -v

4.4.4

Operating system

OS X El Capitan 10.11.6

Browser and version:

N/A - this is in the command line

Reproducible Demo

https://github.com/csalvato/cra-warnings-using-enzyme

@Timer
Copy link
Contributor

Timer commented Apr 9, 2017

Hi, thanks for the bug report, but this is an enzyme bug, not CRA.
Please follow enzymejs/enzyme#875 and enzymejs/enzyme#876 for updates. 😄

@Timer Timer closed this as completed Apr 9, 2017
@csalvato
Copy link
Author

csalvato commented Apr 9, 2017

Huzzah! After posting this, I thought, "Oh my, that is probably an enzyme issue, not a create-react-app issue". Glad to hear that it's reported and being handled.

Thanks for being a gentleman and a scholar, @Timer

@joetidee
Copy link

Could try npm i --save-dev react-test-renderer

cmoesel added a commit to AHRQ-CDS/AHRQ-CDS-Connect-Authoring-Tool that referenced this issue Feb 21, 2018
Running tests emitted some console warnings that were coming from test dependencies.

Fixed this by adding react-test-renderer and updating react-addons-test-utils.

See: facebook/create-react-app#1951
@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants