Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
most basic implementation of adapter calling toTree from react-test-r…
…enderer
- Loading branch information
Pete Gleeson
committed
May 2, 2018
1 parent
024586e
commit f6f6eca
Showing
9 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": ["airbnb"], | ||
"plugins": [ | ||
["transform-replace-object-assign", "object.assign"], | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
_book/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"rules": { | ||
"import/no-extraneous-dependencies": 0, | ||
"import/no-unresolved": 0, | ||
"import/extensions": 0, | ||
"react/no-deprecated": 0, | ||
"react/no-find-dom-node": 0, | ||
"react/no-multi-comp": 0, | ||
"no-underscore-dangle": 0, | ||
"class-methods-use-this": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../enzyme/.npmignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "enzyme-adapter-react-renderer", | ||
"version": "0.0.1", | ||
"description": "JavaScript Testing utilities for React", | ||
"homepage": "http://airbnb.io/enzyme/", | ||
"main": "build", | ||
"scripts": { | ||
"clean": "rimraf build", | ||
"lint": "eslint --ext js,jsx .", | ||
"pretest": "npm run lint", | ||
"prebuild": "npm run clean", | ||
"build": "babel src --out-dir build", | ||
"watch": "npm run build -- -w", | ||
"prepublish": "npm run build && safe-publish-latest" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/airbnb/enzyme.git" | ||
}, | ||
"keywords": [ | ||
"javascript", | ||
"shallow rendering", | ||
"shallowRender", | ||
"test", | ||
"reactjs", | ||
"react", | ||
"flux", | ||
"testing", | ||
"test utils", | ||
"assertion helpers", | ||
"tdd", | ||
"mocha" | ||
], | ||
"author": "Leland Richardson <leland.richardson@airbnb.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"react-test-renderer": "^16.3.2" | ||
}, | ||
"peerDependencies": { | ||
"enzyme": "^3.0.0", | ||
"react": "^16.3.2", | ||
"react-dom": "^16.3.2" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"enzyme": "^3.0.0", | ||
"eslint": "^4.18.0", | ||
"eslint-config-airbnb": "^16.1.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-jsx-a11y": "^6.0.3", | ||
"eslint-plugin-react": "^7.6.1", | ||
"in-publish": "^2.0.0", | ||
"rimraf": "^2.6.2", | ||
"safe-publish-latest": "^1.1.1" | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/enzyme-adapter-react-renderer/src/ReactTestRendererAdapter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { EnzymeAdapter } from 'enzyme'; | ||
import ReactTestRenderer from 'react-test-renderer'; | ||
|
||
class ReactTestRendererAdapter extends EnzymeAdapter { | ||
constructor() { | ||
super(); | ||
} | ||
createMountRenderer(options) { | ||
let instance = null; | ||
return { | ||
render(element) { | ||
instance = ReactTestRenderer.create(element); | ||
}, | ||
getNode() { | ||
return instance.toTree(); | ||
}, | ||
unmount() { | ||
instance.unmount(); | ||
} | ||
}; | ||
} | ||
createRenderer(options) { | ||
switch (options.mode) { | ||
case EnzymeAdapter.MODES.MOUNT: return this.createMountRenderer(options); | ||
default: | ||
throw new Error(`Enzyme Internal Error: Unrecognized mode: ${options.mode}`); | ||
} | ||
} | ||
} | ||
|
||
module.exports = ReactTestRendererAdapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* eslint global-require: 0 */ | ||
module.exports = require('./ReactTestRendererAdapter'); |