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 enzyme usage with test script #771

Closed
menzer opened this issue Sep 26, 2016 · 3 comments
Closed

Support enzyme usage with test script #771

menzer opened this issue Sep 26, 2016 · 3 comments

Comments

@menzer
Copy link

menzer commented Sep 26, 2016

Now that CRA includes a test npm script, with a test environment variable, can #180 be revisited with a test webpack config to enable enzyme usage out of the box?

@gaearon
Copy link
Contributor

gaearon commented Sep 26, 2016

You can already use Enzyme with npm test.
Do you have any specific issues?

We don’t need to add anything to Webpack config because we don’t use Webpack for testing.

I ran

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

and replaced App.test.js with

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

it('renders welcome message', () => {
  const wrapper = shallow(<App />);
  const welcome = <h2>Welcome to React</h2>;
  expect(wrapper.contains(welcome)).toEqual(true);
});

as described in testing guide.

It works:

screen shot 2016-09-26 at 22 49 07

Have I missed something?

@menzer
Copy link
Author

menzer commented Sep 26, 2016

Ah, despite my best efforts to make sure I could reliably repro before opening an issue, I blanked and missed installing react-addons-test-utils in my repro process. I'll close, thanks!

@menzer menzer closed this as completed Sep 26, 2016
@gaearon
Copy link
Contributor

gaearon commented Sep 26, 2016

Yea, that's not super obvious but Enzyme needs it for backward compatibility with React 0.14.

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants