-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Update Enzyme to 3.0 #618
Conversation
Codecov Report
@@ 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.
|
There was a problem hiding this 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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be in devDependencies.
There was a problem hiding this comment.
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 }) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
In a migration guide said that getElement in shallow rendering is getNode method from previous version. |
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>"`; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
7af4717
to
2141791
Compare
Awesome, thanks! 🍕 |
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.