-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Enzyme 3 #198
Enzyme 3 #198
Conversation
you have some linting errors. |
package.json
Outdated
"enzyme": "1.x || ^2.3.0", | ||
"react": "^0.14.0 || ^15.0.0-0", | ||
"react-dom": "^0.14.0 || ^15.0.0-0" | ||
"cheerio": "0.19.x || 0.20.x || 0.22.x || 1.0.0-rc.2", |
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.
enzyme 3 requires cheerio v1 or higher - this needs to change to ^1.0.0-rc.2
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 think #196 has got the dependencies pretty much right
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 as a nonbreaking change #196 does this much better (altho enzyme 2 requires cheerio 0.22 so the 0.19 and 0.20 peer deps aren't helpful)
package.json
Outdated
@@ -58,13 +58,14 @@ | |||
"babel-register": "^6.5.2", | |||
"chai": "^3.0.0 || ^4.0.0", | |||
"cross-env": "3.1.4", | |||
"enzyme": "^2.3.0", | |||
"enzyme": "3.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.
nothing should ever be pinned; these should all use ^
.
package.json
Outdated
"react": "^0.14.0 || ^15.0.0-0", | ||
"react-addons-test-utils": "^0.14.0 || ^15.0.0-0", | ||
"react-dom": "^0.14.0 || ^15.0.0-0", | ||
"react": "16.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.
dev dep ranges should always exactly match peer dep ranges.
@@ -2,6 +2,8 @@ import $ from 'cheerio' | |||
|
|||
import TestWrapper from './TestWrapper' | |||
|
|||
const getDisplayName = type => type.displayName || type.name || type |
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 is this function needed?
src/ShallowTestWrapper.js
Outdated
|
||
const rootInstance = root.instance() | ||
const rootType = rootInstance ? rootInstance.constructor : root.getElement().type | ||
const name = rootType ? getDisplayName(rootType) : '???' |
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.
root.name() || '???'
should suffice here, no?
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.
Enzyme's ShallowWrapper
behaves slightly different from the ReactWrapper
when it comes to the name()
function. Given the following component:
const Example = () => <table />;
mount(<Example />).name()
returns 'Example'
while shallow(<Example />).name()
returns 'table'
.
Is there a way that we can get this expedited? With React 16 and enzyme 3 being released last night, this is the final piece for many upgrading. Thanks! |
@@ -1,8 +1,10 @@ | |||
class Fixture extends React.Component { | |||
render () { | |||
return ( | |||
<div id='parent'> | |||
<div id='child' /> | |||
<div> |
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 are all these necessary?
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.
Enzyme 3 changes the way it wraps HTML when returning from the render
function. The new version returns a cheerio wrapper with a type of tag
that IS the parent element (instead of a wrapper with a type root
that contains the parent element).
For example:
<div id='parent'>
<div id='child' />
<div>
With the above code in Enzyme 3, calling wrapper.find('#parent').length
returns 0
while calling wrapper.is('#parent')
returns true
. With Enzyme 2, wrapper.find('#parent').length
returns 1
and wrapper.is('#parent')
returns false
.
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.
(this is as a result of a breaking change in cheerio v1)
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.
Thanks for explaining, we'll definitely have to document this in our CHANGELOG.md
to educate people on how to upgrade
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.
Crazy 3AM idea (jetlag), can we add the extra <div />
in chai-enzyme when using render
?
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.
You could wrap it, sure, but then anyone who didn't understand this, and was checking any other method besides .html()
, would have the wrong assertions.
In other words, it's better for wrapper.is('#parent') === true
and wrapper.html()
not to contain the parent div, then for the reverse to be true.
Can you get rid of the |
I'd suggest adding |
@marchaos we're trying to release a react 16 compatible version as soon as possible. Any help is appreciated :) |
@ljharb I just pulled this branch down and ran it, but the tests are passing on my end. It's difficult to see the problem on TravisCI because the jobs are halting on the previously-identified linting error. It doesn't look like any new commits have been push up, so I think I may be doing something wrong here. Should I be using some command other than |
@jugglinmike travis only runs https://github.com/producthunt/chai-enzyme/blob/master/.travis.yml#L12-L14 - that should be sufficient. |
Still no dice, I'm afraid. The command
Finishes with:
For context:
|
Two pull requests will do that :-).
Are the two active pull requests racing against each other? What's going on.
On 28 Sep. 2017 6:39 am, "jugglinmike" <[email protected]> wrote:
Uhg. @ljharb <https://github.com/ljharb> I somehow confused this branch
with gh-196 <#196
where you actually asked for my input. Sorry for the noise, folks.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#198 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGfHne5zQnpZA7y5zRDmt651kWqZHzA5ks5smrJvgaJpZM4PlF69>
.
|
Bah. Sorry, I didn't realize there was an existing PR. @jugglinmike, I'm happy to concede the honor to you. Feel free to use anything in this one that helps. |
Actually, that one isn't mine. I'm just trying to help with integration issues (though it seems you've solved those here). |
@rylanc it's always ideal to avoid breaking changes if possible :-) |
In order to satisfy the
function reactElementToJSXString(node) {
const Wrapper = () => node
return shallow(<Wrapper />).debug()
} I'd lean towards the latter, if it were up to me. Let me know what you think |
@ljharb The tests are passing for both enzyme 2 and 3 now if you have time to take another look. |
@rylanc I'm ok dropping |
@rylanc improving |
package.json
Outdated
"react": "^0.14.0 || ^15.0.0-0", | ||
"react-dom": "^0.14.0 || ^15.0.0-0" | ||
"cheerio": "0.19.x || 0.20.x || 0.22.x || ^1.0.0-0", | ||
"enzyme": "^2.9.1 || ^3.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.
Out of curiosity, is it possible to support "^2.7.0 || ^3.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.
Yup. Done!
@@ -13,7 +13,7 @@ export default function wrap (el) { | |||
return new ReactTestWrapper(el) | |||
} | |||
|
|||
if (el && el._root && el.options) { | |||
if (el && el.cheerio && el.options) { |
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.
This doesn't need a fallback (to _root
for old cheerio versions)?
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.
It looks Cheerio.prototype.cheerio
has been around since 0.19.0
: https://github.com/cheeriojs/cheerio/blob/0.19.0/lib/cheerio.js#L99
"react": "^0.14.0 || ^15.0.0-0", | ||
"react-dom": "^0.14.0 || ^15.0.0-0" | ||
"cheerio": "0.19.x || 0.20.x || 0.22.x || ^1.0.0-0", | ||
"enzyme": "^2.7.0 || ^3.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.
this is semver-major since it's dropping v1, but i don't think it's worth retaining v1 support either.
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.
Good point. Since the current version is still < 1.0, does this make it 0.9.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.
IMO we release a 1.0 when this PR is merged in so I wouldn't worry about it
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.
1.0 is always good :-) if it remained sub-1.0 for some reason then it'd be 0.9.0
, yes
|
||
function reactElementToJSXString (node) { | ||
const Wrapper = () => node | ||
return shallow(<Wrapper />).debug() |
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.
Hey @rylanc I am not sure, if I can comment on this, but I found this while using your changes. Hence, bring to your notice. We need import React from 'react'
before creating a react element 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.
eslint-plugin-react should be used to lint for this, fwiw.
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 the airbnb eslint config has it all set up for you ;-) )
No description provided.