-
-
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
Changes from 3 commits
174bcef
b954dd5
1afa0ca
baf4a40
629c0fa
e443235
f9a6123
12e3050
6bbcd87
f948940
31ad72e
0bc48dc
02f7f3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,10 @@ | |
}, | ||
"peerDependencies": { | ||
"chai": "^3.0.0 || ^4.0.0", | ||
"cheerio": "0.19.x || 0.20.x || 0.22.x || 1.0.0-rc.1", | ||
"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", | ||
"enzyme": "^3.0.0", | ||
"react": "^0.14.0 || ^15.0.0-0 || ^16.0.0", | ||
"react-dom": "^0.14.0 || ^15.0.0-0 || ^16.0.0" | ||
}, | ||
"keywords": [ | ||
"javascript", | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. nothing should ever be pinned; these should all use |
||
"enzyme-adapter-react-16": "1.0.0", | ||
"jsdom": "^9.1.0", | ||
"mocha": "^3.0.0", | ||
"prop-types": "^15.5.7", | ||
"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 commentThe reason will be displayed to describe this comment to others. Learn more. dev dep ranges should always exactly match peer dep ranges. |
||
"react-dom": "16.0.0", | ||
"react-test-renderer": "16.0.0", | ||
"rimraf": "^2.5.0", | ||
"snazzy": "^5.0.0", | ||
"standard": "^8.1.0" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. why is this function needed? |
||
|
||
export default class ShallowTestWrapper extends TestWrapper { | ||
constructor (wrapper) { | ||
super() | ||
|
@@ -17,11 +19,13 @@ export default class ShallowTestWrapper extends TestWrapper { | |
} | ||
|
||
inspect () { | ||
const name = this.wrapper.root.unrendered.type.displayName || | ||
this.wrapper.root.unrendered.type.name || | ||
'???' | ||
const root = this.wrapper.root() | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enzyme's const Example = () => <table />;
|
||
|
||
if (this.wrapper.root === this.wrapper) { | ||
if (root === this.wrapper) { | ||
return `<${name} />` | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't need a fallback (to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks |
||
return new CheerioTestWrapper(el) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Enzyme 3 changes the way it wraps HTML when returning from the For example: <div id='parent'>
<div id='child' />
<div> With the above code in Enzyme 3, calling There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for explaining, we'll definitely have to document this in our There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Crazy 3AM idea (jetlag), can we add the extra There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 In other words, it's better for |
||
<div id='parent'> | ||
<div id='child' /> | ||
</div> | ||
</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.
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)