Skip to content

Commit

Permalink
Merge branch 'master' into fix-cDU-on-setState
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 authored Nov 3, 2017
2 parents 40e38aa + 32b5118 commit ca9b440
Show file tree
Hide file tree
Showing 27 changed files with 353 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sudo: false
matrix:
fast_finish: true
include:
- node_js: "node"
- node_js: "lts/*"
env: LINT=true
- node_js: "6"
env: KARMA=true REACT=0.13
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Enzyme
[![Join the chat at https://gitter.im/airbnb/enzyme](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/airbnb/enzyme?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![npm Version](https://img.shields.io/npm/v/enzyme.svg)](https://www.npmjs.com/package/enzyme) [![License](https://img.shields.io/npm/l/enzyme.svg)](https://www.npmjs.com/package/enzyme) [![Build Status](https://travis-ci.org/airbnb/enzyme.svg)](https://travis-ci.org/airbnb/enzyme) [![Coverage Status](https://coveralls.io/repos/airbnb/enzyme/badge.svg?branch=master&service=github)](https://coveralls.io/github/airbnb/enzyme?branch=master)
[![Discord Channel](https://img.shields.io/badge/discord-testing@reactiflux-738bd7.svg?style=flat-square)](https://discord.gg/0ZcbPKXt5bY8vNTA)


Enzyme is a JavaScript Testing utility for React that makes it easier to assert, manipulate,
Expand Down
2 changes: 1 addition & 1 deletion docs/api/ShallowWrapper/setProps.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ NOTE: can only be called on a wrapper instance that is also the root instance.

#### Arguments

1. `nextProps` (`Object`): An object containing new props to merge in with the current state
1. `nextProps` (`Object`): An object containing new props to merge in with the current props



Expand Down
6 changes: 6 additions & 0 deletions docs/installation/react-014.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ installed, you should do so:
npm i --save react@0.14 react-dom@0.14
```

Further, enzyme with React 0.14 requires the test utilities addon be installed:

```bash
npm i --save-dev react-addons-test-utils@0.14
```

Next, to get started with enzyme, you can simply install it with npm:

```bash
Expand Down
6 changes: 6 additions & 0 deletions docs/installation/react-15.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ installed, you should do so:
npm i --save react@15 react-dom@15
```

Further, enzyme requires the test utilities addon be installed:

```bash
npm i --save-dev react-test-renderer@15
```

Next, to get started with enzyme, you can simply install it with npm:

```bash
Expand Down
2 changes: 2 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var root = process.cwd();
var adapterName = 'enzyme-adapter-react-' + version;
var adapterPackageJsonPath = path.join(root, 'packages', adapterName, 'package.json');
var testPackageJsonPath = path.join(root, 'packages', 'enzyme-test-suite', 'package.json');
var utilsPackageJsonPath = path.join(root, 'packages', 'enzyme-adapter-utils', 'package.json');

if (!fs.statSync(adapterPackageJsonPath)) {
throw new Error('Adapter not found: "' + adapterName + '"');
Expand Down Expand Up @@ -66,6 +67,7 @@ Promise.resolve()
.then(() => Promise.all([
getJSON(adapterPackageJsonPath),
getJSON(testPackageJsonPath),
getJSON(utilsPackageJsonPath),
]))
.then(([adapterJson, testJson]) => {
const peerDeps = adapterJson.peerDependencies;
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme-adapter-react-13/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enzyme-adapter-react-13",
"version": "1.0.1",
"version": "1.0.2",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
Expand Down Expand Up @@ -31,7 +31,7 @@
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"dependencies": {
"enzyme-adapter-utils": "^1.0.0",
"enzyme-adapter-utils": "^1.1.0",
"lodash": "^4.17.4",
"object.assign": "^4.0.4",
"object.values": "^1.0.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import flatten from 'lodash/flatten';
import { flatten, isArrayLike } from 'enzyme-adapter-utils';

export function nodeTypeFromType(type) {
if (typeof type === 'string') {
Expand All @@ -21,8 +21,8 @@ export default function elementToTree(el) {
const { type, props, key, ref } = el;
const { children } = props;
let rendered = null;
if (Array.isArray(children)) {
rendered = flatten(children, true).map(elementToTree);
if (isArrayLike(children)) {
rendered = flatten([...children], true).map(elementToTree);
} else if (typeof children !== 'undefined') {
rendered = elementToTree(children);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/enzyme-adapter-react-14/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enzyme-adapter-react-14",
"version": "1.0.2",
"version": "1.0.4",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
Expand Down Expand Up @@ -34,16 +34,16 @@
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"dependencies": {
"enzyme-adapter-utils": "^1.0.0",
"enzyme-adapter-utils": "^1.1.0",
"lodash": "^4.17.4",
"object.assign": "^4.0.4",
"object.values": "^1.0.4",
"prop-types": "^15.5.10",
"react-addons-test-utils": "^0.14.0"
"prop-types": "^15.5.10"
},
"peerDependencies": {
"enzyme": "^3.0.0",
"react": "^0.14.0",
"react-addons-test-utils": "^0.14.0",
"react-dom": "^0.14.0"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/enzyme-adapter-react-15.4/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enzyme-adapter-react-15.4",
"version": "1.0.2",
"version": "1.0.4",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
Expand Down Expand Up @@ -34,17 +34,17 @@
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"dependencies": {
"enzyme-adapter-utils": "^1.0.0",
"enzyme-adapter-utils": "^1.1.0",
"lodash": "^4.17.4",
"object.assign": "^4.0.4",
"object.values": "^1.0.4",
"prop-types": "^15.5.10",
"react-addons-test-utils": "15.0.0-0 - 15.4.x"
"prop-types": "^15.5.10"
},
"peerDependencies": {
"enzyme": "^3.0.0",
"react": "15.0.0-0 - 15.4.x",
"react-dom": "15.0.0-0 - 15.4.x"
"react-dom": "15.0.0-0 - 15.4.x",
"react-addons-test-utils": "15.0.0-0 - 15.4.x"
},
"devDependencies": {
"babel-cli": "^6.24.1",
Expand Down
11 changes: 6 additions & 5 deletions packages/enzyme-adapter-react-15/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enzyme-adapter-react-15",
"version": "1.0.2",
"version": "1.0.4",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
Expand Down Expand Up @@ -34,20 +34,21 @@
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"dependencies": {
"enzyme-adapter-utils": "^1.0.0",
"enzyme-adapter-utils": "^1.1.0",
"lodash": "^4.17.4",
"object.assign": "^4.0.4",
"object.values": "^1.0.4",
"prop-types": "^15.5.10",
"react-test-renderer": "^15.5.0"
"prop-types": "^15.5.10"
},
"peerDependencies": {
"enzyme": "^3.0.0",
"react": "^15.5.0",
"react-dom": "^15.5.0"
"react-dom": "^15.5.0",
"react-test-renderer": "^15.5.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-plugin-transform-replace-object-assign": "^0.2.1",
"enzyme": "^3.0.0",
"eslint": "^4.4.1",
"in-publish": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme-adapter-react-16/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enzyme-adapter-react-16",
"version": "1.0.2",
"version": "1.0.3",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
Expand Down Expand Up @@ -34,7 +34,7 @@
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"dependencies": {
"enzyme-adapter-utils": "^1.0.0",
"enzyme-adapter-utils": "^1.1.0",
"lodash": "^4.17.4",
"object.assign": "^4.0.4",
"object.values": "^1.0.4",
Expand Down
3 changes: 2 additions & 1 deletion packages/enzyme-adapter-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enzyme-adapter-utils",
"version": "1.0.1",
"version": "1.1.0",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
Expand Down Expand Up @@ -43,6 +43,7 @@
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-plugin-transform-replace-object-assign": "^0.2.1",
"eslint": "^4.4.1",
"in-publish": "^2.0.0",
"rimraf": "^2.6.1",
Expand Down
25 changes: 22 additions & 3 deletions packages/enzyme-adapter-utils/src/Utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import flatten from 'lodash/flatten';
import createMountWrapper from './createMountWrapper';
import createRenderWrapper from './createRenderWrapper';

Expand Down Expand Up @@ -95,15 +94,35 @@ export function nodeTypeFromType(type) {
return 'function';
}

function isIterable(obj) {
return (
obj != null &&
typeof Symbol === 'function' &&
typeof Symbol.iterator === 'symbol' &&
typeof obj[Symbol.iterator] === 'function'
);
}

export function isArrayLike(obj) {
return Array.isArray(obj) || (isIterable(obj) && typeof obj !== 'string');
}

export function flatten(arrs) {
return arrs.reduce(
(flattened, item) => flattened.concat(isArrayLike(item) ? flatten([...item]) : item),
[],
);
}

export function elementToTree(el) {
if (el === null || typeof el !== 'object' || !('type' in el)) {
return el;
}
const { type, props, key, ref } = el;
const { children } = props;
let rendered = null;
if (Array.isArray(children)) {
rendered = flatten(children, true).map(elementToTree);
if (isArrayLike(children)) {
rendered = flatten([...children], true).map(elementToTree);
} else if (typeof children !== 'undefined') {
rendered = elementToTree(children);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/enzyme-example-mocha/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["airbnb"]
}
8 changes: 8 additions & 0 deletions packages/enzyme-example-mocha/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "airbnb",
"root": true,
"env": {
"node": true,
"mocha": true
}
}
22 changes: 22 additions & 0 deletions packages/enzyme-example-mocha/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Dependency directory
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# Coverage
.coverage
.nyc_output
9 changes: 9 additions & 0 deletions packages/enzyme-example-mocha/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"reporter": [
"lcov",
"text-summary"
],
"extension": [
".jsx"
]
}
21 changes: 21 additions & 0 deletions packages/enzyme-example-mocha/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Leland Richardson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions packages/enzyme-example-mocha/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# enzyme-example-mocha
Example project with React + Enzyme + Mocha

# npm scripts
```
npm test
```
38 changes: 38 additions & 0 deletions packages/enzyme-example-mocha/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "enzyme-example-mocha",
"version": "0.1.0",
"description": "Example project with React + Enzyme + Mocha",
"scripts": {
"lint": "eslint ./src/**/*.js*",
"pretest": "npm run lint",
"test": "nyc mocha --require test/.setup.js --compilers js:babel-core/register src/*.spec.js*",
"test-watch": "npm test -- --watch"
},
"repository": {
"type": "git",
"url": "https://github.com/airbnb/enzyme.git"
},
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"homepage": "https://github.com/airbnb/enzyme.git",
"devDependencies": {
"babel": "^6.23.0",
"babel-core": "^6.26.0",
"babel-preset-airbnb": "^2.4.0",
"eslint": "^4.9.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.4.0",
"jsdom": "^11.3.0",
"mocha": "^3.5.3",
"nyc": "^11.2.1"
},
"dependencies": {
"chai": "^3.5.0",
"enzyme": "^3.0.0",
"enzyme-adapter-react-16": "^1.0.0",
"react": "^16.0.0",
"react-dom": "^16.0.0"
}
}
5 changes: 5 additions & 0 deletions packages/enzyme-example-mocha/src/Foo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const Foo = () => <div className="foo" />;

export default Foo;
Loading

0 comments on commit ca9b440

Please sign in to comment.