diff --git a/.travis.yml b/.travis.yml
index 7f414ee..cf71f54 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,7 +8,11 @@ node_js:
env:
- CHAI_VERSION=^3.0.0
- CHAI_VERSION=^4.0.0
+ - ENZYME_VERSION=^2
+ - ENZYME_VERSION=^3
before_script:
- npm install chai@$CHAI_VERSION
+ - if [ "$ENZYME_VERSION" = "^2" ]; then npm uninstall enzyme-adapter-react-15; npm install cheerio@0.22; fi
+ - npm install enzyme@$ENZYME_VERSION
script:
- npm test
diff --git a/package.json b/package.json
index f9108e7..ddbf9c0 100644
--- a/package.json
+++ b/package.json
@@ -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-0",
+ "enzyme": "^2.7.0 || ^3.0.0",
+ "react": "^0.14.0 || ^15.0.0-0 || ^16.0.0-0",
+ "react-dom": "^0.14.0 || ^15.0.0-0 || ^16.0.0-0"
},
"keywords": [
"javascript",
@@ -57,14 +57,15 @@
"babel-preset-react": "^6.5.0",
"babel-register": "^6.5.2",
"chai": "^3.0.0 || ^4.0.0",
- "cross-env": "3.1.4",
- "enzyme": "^2.3.0",
+ "cross-env": "^3.1.4",
+ "enzyme": "^2.7.0 || ^3.0.0",
+ "enzyme-adapter-react-15": "^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": "^15.6.2",
+ "react-dom": "^15.6.2",
+ "react-test-renderer": "^15.6.2",
"rimraf": "^2.5.0",
"snazzy": "^5.0.0",
"standard": "^8.1.0"
@@ -80,11 +81,11 @@
"afterEach",
"React",
"expect",
- "createTest"
+ "createTest",
+ "isEnzyme3"
]
},
"dependencies": {
- "html": "^1.0.0",
- "react-element-to-jsx-string": "^5.0.0"
+ "html": "^1.0.0"
}
}
diff --git a/src/ChaiWrapper.js b/src/ChaiWrapper.js
index ef684f4..791a199 100644
--- a/src/ChaiWrapper.js
+++ b/src/ChaiWrapper.js
@@ -1,7 +1,6 @@
import wrap from './wrap'
export default class ChaiWrapper {
-
/**
* Constructs a instance of the chai wrapper.
*
diff --git a/src/CheerioTestWrapper.js b/src/CheerioTestWrapper.js
index 6aec4e2..273ad4e 100644
--- a/src/CheerioTestWrapper.js
+++ b/src/CheerioTestWrapper.js
@@ -8,10 +8,9 @@ export default class CheerioTestWrapper extends TestWrapper {
get el () {
if (!this.__el) {
- if (this.wrapper.first()['0'].type === 'root') {
+ this.__el = this.wrapper.first()
+ if (this.__el.length > 0 && this.__el['0'].type === 'root') {
this.__el = this.wrapper.children().first()
- } else {
- this.__el = this.wrapper.first()
}
}
diff --git a/src/ReactTestWrapper.js b/src/ReactTestWrapper.js
index afaeaab..7e3055c 100644
--- a/src/ReactTestWrapper.js
+++ b/src/ReactTestWrapper.js
@@ -1,5 +1,3 @@
-import {findDOMNode} from 'enzyme/build/react-compat'
-
import TestWrapper from './TestWrapper'
export default class ReactTestWrapper extends TestWrapper {
@@ -10,18 +8,17 @@ export default class ReactTestWrapper extends TestWrapper {
get el () {
if (!this.__el) {
- this.__el = this.wrapper.single((n) => findDOMNode(n))
+ this.__el = this.wrapper.getDOMNode()
}
return this.__el
}
inspect () {
- const name = this.wrapper.root.node.constructor.displayName ||
- this.wrapper.root.node.constructor.name ||
- '???'
+ const root = this.root()
+ const name = root.name() || '???'
- if (this.wrapper.root === this.wrapper) {
+ if (root === this.wrapper) {
return `<${name} />`
}
diff --git a/src/ShallowTestWrapper.js b/src/ShallowTestWrapper.js
index 4707bb4..6a3edac 100644
--- a/src/ShallowTestWrapper.js
+++ b/src/ShallowTestWrapper.js
@@ -2,6 +2,8 @@ import $ from 'cheerio'
import TestWrapper from './TestWrapper'
+const getDisplayName = type => type.displayName || type.name || type
+
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.root()
+
+ const rootInstance = root.instance()
+ const rootType = rootInstance && rootInstance.constructor
+ const name = rootType ? getDisplayName(rootType) : (root.name() || '???')
- if (this.wrapper.root === this.wrapper) {
+ if (root === this.wrapper) {
return `<${name} />`
}
diff --git a/src/TestWrapper.js b/src/TestWrapper.js
index e91acc1..d48f50d 100644
--- a/src/TestWrapper.js
+++ b/src/TestWrapper.js
@@ -38,4 +38,8 @@ export default class TestWrapper {
text () {
return this.wrapper.text()
}
+
+ root () {
+ return (typeof this.wrapper.root === 'function') ? this.wrapper.root() : this.wrapper.root
+ }
}
diff --git a/src/assertions/containMatchingElement.js b/src/assertions/containMatchingElement.js
index 00bc7d4..447e53d 100644
--- a/src/assertions/containMatchingElement.js
+++ b/src/assertions/containMatchingElement.js
@@ -1,7 +1,7 @@
-import reactElementToJSXString from 'react-element-to-jsx-string'
+import reactNodeToString from '../reactNodeToString'
export default function containMatchingElement ({ wrapper, markup, arg1, sig }) {
- const arg1JSXString = reactElementToJSXString(arg1)
+ const arg1JSXString = reactNodeToString(arg1)
this.assert(
wrapper.wrapper.containsMatchingElement(arg1),
diff --git a/src/reactNodeToString.js b/src/reactNodeToString.js
index 0dbc78b..85f06ac 100644
--- a/src/reactNodeToString.js
+++ b/src/reactNodeToString.js
@@ -1,4 +1,9 @@
-import reactElementToJSXString from 'react-element-to-jsx-string'
+import { shallow } from 'enzyme'
+
+function reactElementToJSXString (node) {
+ const Wrapper = () => node
+ return shallow(