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

Update Enzyme to 3.0 #618

Merged
merged 6 commits into from
Oct 2, 2017
Merged

Conversation

lutien
Copy link
Collaborator

@lutien lutien commented Sep 30, 2017

Updating Enzyme and enzyme-to-json to the last versions with an adapter for react 15.
Tests are updated to work with new versions.
Should help to migrate tests to react 16.

@codecov-io
Copy link

codecov-io commented Sep 30, 2017

Codecov Report

Merging #618 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #618   +/-   ##
=======================================
  Coverage   96.09%   96.09%           
=======================================
  Files         100      100           
  Lines        1330     1330           
  Branches      270      270           
=======================================
  Hits         1278     1278           
  Misses         50       50           
  Partials        2        2

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a9d184f...2141791. Read the comment docs.

Copy link
Member

@sapegin sapegin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much!

Could you point me to the docs about the difference between getElement and getDOMNode?

package.json Outdated
@@ -41,6 +41,7 @@
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.7",
"doctrine": "^2.0.0",
"enzyme-adapter-react-15": "^1.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be in devDependencies.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, true. Fixed.

const actual = shallow(<Preview code={code} evalInContext={evalInContext} />, options);
const actual = shallow(
<Preview code={code} evalInContext={evalInContext} />,
Object.assign({}, options, { disableLifecycleMethods: true })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need disableLifecycleMethods here? What was changed in Enzyme?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before in shallow rendering lifecycle methods didn`t work by default. Now they do

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@lutien
Copy link
Collaborator Author

lutien commented Oct 1, 2017

In a migration guide said that getElement in shallow rendering is getNode method from previous version.
http://airbnb.io/enzyme/docs/guides/migration-from-2-to-3.html#with-shallow-getnode-should-be-replaced-with-getelement
It means this is a documentation for getElement - http://airbnb.io/enzyme/docs/api/ShallowWrapper/getNode.md
And this is for getDOMNode http://airbnb.io/enzyme/docs/api/ReactWrapper/getDOMNode.md

@sapegin
Copy link
Member

sapegin commented Oct 1, 2017

I see, make sense!

@@ -1,19 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Markdown should render Markdown in span in inline mode 1`] = `"<span class=\\"rsg--base-0\\">Hello <em class=\\"rsg--em-16 rsg--base-0\\">world</em>!</span>"`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you take a look why these wrappers have disappeared?

Copy link
Collaborator Author

@lutien lutien Oct 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I've investigated a bit. The reason for it you can find here - enzymejs/enzyme#1162
The short answer is that it happened because of breaking changes in cheerio which is used for render in enzyme. But we actually can get these wrappers back if instead of doing this
expect(render(<Test />).html()).toMatchSnapshot();
we will do this
import cheerio from 'cheerio'; expect(cheerio.html(render(<Test />))).toMatchSnapshot();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn’t look very nice but I think it would make sense to use this because we want to change the wrapper too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And done

@@ -78,7 +79,6 @@ it('should open a code editor', done => {

setTimeout(() => {
expect(actual.find(reactCodeMirrorSelector)).toHaveLength(1);
done();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why done was removed? This test is still async. Looks like I’m missing something here :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought with expect.assertions(1); it would work as with promises, but no :(
Test failed before but the reason was not here, now it should work properly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect.assertions just tells Jest how many assertions to expect and it would fail the test after a timeout if there were less assertions.

@lutien lutien force-pushed the update-enzyme-to-3 branch from 7af4717 to 2141791 Compare October 2, 2017 09:14
@sapegin sapegin merged commit 0f06fcc into styleguidist:master Oct 2, 2017
@sapegin
Copy link
Member

sapegin commented Oct 2, 2017

Awesome, thanks! 🍕

@sapegin sapegin mentioned this pull request Oct 4, 2017
17 tasks
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

Successfully merging this pull request may close these issues.

3 participants