Skip to content

Commit

Permalink
Merge branch 'master' into portals
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense authored Nov 6, 2017
2 parents eb4c364 + 29aab57 commit c26a615
Show file tree
Hide file tree
Showing 60 changed files with 2,026 additions and 1,530 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_book/
build/
node_modules/
**/node_modules/
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 3.1.1

### Fixes

- @koba04: Fix to call componentDidUpdate on setState of React v16 ([#1261](https://github.com/airbnb/enzyme/pull/1261))

## 3.1.0

### New Stuff
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ npm run react:14
npm run react:15
```

```bash
# switch to React 16
npm run react:16
```

### Running Tests

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/ReactWrapper/setContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import React from 'react';
import PropTypes from 'prop-types';

function SimpleComponent(props, context) {
return <div>{name}</div>;
return <div>{context.name}</div>;
}
SimpleComponent.contextTypes = {
name: PropTypes.string,
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
74 changes: 40 additions & 34 deletions docs/api/selector.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# enzyme Selectors

Many methods in enzyme's API accept a *selector* as an argument. Selectors in enzyme can fall into
one of the following four categories:
Many methods in enzyme’s API accept a *selector* as an argument. Selectors in enzyme can fall into
one of the following five categories:



### 1. A Valid CSS Selector
Expand All @@ -10,58 +11,62 @@ enzyme supports a subset of valid CSS selectors to find nodes inside a render tr
follows:

- class syntax (`.foo`, `.foo-bar`, etc.)
- tag syntax (`input`, `div`, `span`, etc.)
- element syntax (`input`, `div`, `span`, etc.)
- id syntax (`#foo`, `#foo-bar`, etc.)
- prop syntax (`[htmlFor="foo"]`, `[bar]`, `[baz=1]`, etc.);

**Note -- Prop selector**
Strings, numeric literals and boolean property values are supported for prop syntax
in combination of the expected string syntax. For example, the following
is supported:

```js
const wrapper = mount((
<div>
<span foo={3} bar={false} title="baz" />
</div>
));

wrapper.find('[foo=3]');
wrapper.find('[bar=false]');
wrapper.find('[title="baz"]');
```
- attribute syntax (`[href="foo"]`, `[type="text"]`, etc.)

Further, enzyme supports combining any of those supported syntaxes together to uniquely identify a
single node. For instance:
single node. For instance:

```css
div.foo.bar
input#input-name
label[foo=true]
a[href="foo"]
```

enzyme also gives support for the following contextual selectors

```
```css
.foo .bar
.foo > .bar
.foo + .bar
.foo ~ .bar
.foo input
```


**Want more CSS support?**

PR's implementing more support for CSS selectors will be accepted and is an area of development for
PRs implementing more support for CSS selectors will be accepted and is an area of development for
enzyme that will likely be focused on in the future.



### 2. A React Component Constructor
### 2. Prop Selector

In addition to traditional CSS selectors, enzyme supports using a React prop like an Attribute Selector as if it were an HTML attribute. Strings, Numbers, and Boolean property values are supported.

```js
const wrapper = mount((
<div>
<span foo={3} bar={false} title="baz" />
</div>
));

wrapper.find('[foo=3]');
wrapper.find('[bar=false]');
wrapper.find('[title="baz"]');
```

**The Key and Ref Prop**

While in most cases, any React prop can be used, there are exceptions. The `key` and `ref` props will never work. This decision comes from how React uses these props internally, which means they should not be relied upon.



### 3. A React Component Constructor

enzyme allows you to find components based on their constructor. You can pass in the reference to
the component's constructor:
the components constructor:

```jsx
function MyComponent() {
Expand All @@ -74,9 +79,9 @@ const myComponents = wrapper.find(MyComponent);



### 3. A React Component's displayName
### 4. A React Components displayName

enzyme allows you to find components based on a component's `displayName`. If a component exists
enzyme allows you to find components based on a components `displayName`. If a component exists
in a render tree where its `displayName` is set and has its first character as a capital letter,
a string can be used to find it:

Expand All @@ -91,13 +96,13 @@ MyComponent.displayName = 'My Component';
const myComponents = wrapper.find('My Component');
```

NOTE: This will *only* work if the selector (and thus the component's `displayName`) is a string
NOTE: This will *only* work if the selector (and thus the components `displayName`) is a string
starting with a capital letter. Strings starting with lower case letters will assume it is a CSS
selector using the tag syntax.



### 4. Object Property Selector
### 5. Object Property Selector

enzyme allows you to find components and nodes based on a subset of their properties:

Expand All @@ -114,8 +119,9 @@ wrapper.find({ bar: false });
wrapper.find({ title: 'baz' });
```

**Note - undefined properties**
are not allowed in the object property selector and will cause an error:
**Undefined Properties**

Undefined properties are not allowed in the object property selector and will cause an error:


```jsx
Expand Down
5 changes: 1 addition & 4 deletions docs/api/shallow.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ describe('<MyComponent />', () => {
- `options.context`: (`Object` [optional]): Context to be passed into the component
- `options.disableLifecycleMethods`: (`Boolean` [optional]): If set to true, `componentDidMount`
is not called on the component, and `componentDidUpdate` is not called after
[`setProps`](ShallowWrapper/setProps.md) and [`setContext`](ShallowWrapper/setContext.md). Default to `false`.
- `options.lifecycleExperimental`: (`Boolean` [optional]): If set to true, the entire lifecycle
(`componentDidMount` and `componentDidUpdate`) of the React component is called. The current default value
is `false` with enzyme v2, but the next major version will flip the default value to `true`.
[`setProps`](ShallowWrapper/setProps.md) and [`setContext`](ShallowWrapper/setContext.md). Default to `false`.

#### Returns

Expand Down
2 changes: 1 addition & 1 deletion docs/common-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ class Comp extends React.Component {
}

const wrapper = mount(<Comp />);
const portal = wrapper.instance().portal;
const { portal } = wrapper.instance();
// assert on `portal`
```
2 changes: 1 addition & 1 deletion docs/guides/jest.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Starting with version 15, Jest [no longer mocks modules by default](https://facebook.github.io/jest/blog/2016/09/01/jest-15.html). Because of this, you no longer have to add _any_ special configuration for Jest to use it with enzyme.

Install Jest, and its Babel integrations, as recommended in the [Jest docs](https://facebook.github.io/jest/docs/getting-started.html). Install enzyme. Then, simply require/import React, enzyme functions, and your module at the top of a test file.
Install Jest, and its Babel integrations, as recommended in the [Jest docs](https://facebook.github.io/jest/docs/en/getting-started.html). Install enzyme. Then, simply require/import React, enzyme functions, and your module at the top of a test file.

```js
import React from 'react';
Expand Down
12 changes: 9 additions & 3 deletions docs/guides/jsdom.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const { window } = jsdom;
function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.map(prop => Object.getOwnPropertyDescriptor(src, prop));
.reduce((result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(src, prop),
}), {});
Object.defineProperties(target, props);
}

Expand All @@ -43,7 +46,7 @@ Here is the sample of [jsdom old API](https://github.com/tmpvar/jsdom/blob/maste
```js
/* setup.js */

const jsdom = require('jsdom').jsdom;
const { jsdom } = require('jsdom');

global.document = jsdom('');
global.window = document.defaultView;
Expand All @@ -54,7 +57,10 @@ global.navigator = {
function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.map(prop => Object.getOwnPropertyDescriptor(src, prop));
.reduce((result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(src, prop),
}), {});
Object.defineProperties(target, props);
}
copyProps(document.defaultView, global);
Expand Down
6 changes: 0 additions & 6 deletions docs/installation/react-16.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ installed, you should do so:
npm i --save react@16 react-dom@16
```

Further, enzyme requires the test utilities addon be installed:

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

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
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,22 @@
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"devDependencies": {
"prop-types": "^15.5.10",
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^6.4.1",
"babel-plugin-transform-replace-object-assign": "^0.2.1",
"babel-preset-airbnb": "^2.4.0",
"babel-register": "^6.24.1",
"babel-register": "^6.26.0",
"chai": "^4.1.1",
"coveralls": "^2.13.1",
"create-react-class": "^15.6.0",
"eslint": "^4.4.1",
"eslint-config-airbnb": "^15.1.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^5.0.3",
"eslint": "^4.10.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-markdown": "^1.0.0-beta.6",
"eslint-plugin-react": "^7.2.1",
"eslint-plugin-react": "^7.4.0",
"gitbook-cli": "^1.0.1",
"gitbook-plugin-anchors": "^0.7.1",
"gitbook-plugin-codeblock-disable-glossary": "0.0.1",
Expand All @@ -99,9 +98,10 @@
"karma-webpack": "^1.8.1",
"lerna": "^2.0.0",
"mocha": "^3.5.0",
"rimraf": "^2.6.1",
"prop-types": "^15.6.0",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.1",
"sinon": "^2.4.1",
"sinon": "^4.1.0",
"webpack": "^1.13.3"
},
"dependencies": {}
Expand Down
14 changes: 9 additions & 5 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.3",
"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 All @@ -42,10 +42,14 @@
"react": "^0.13.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-cli": "^6.26.0",
"enzyme": "^3.0.0",
"eslint": "^4.4.1",
"eslint": "^4.10.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",
"in-publish": "^2.0.0",
"rimraf": "^2.6.1"
"rimraf": "^2.6.2"
}
}
6 changes: 3 additions & 3 deletions packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function instanceToTree(inst) {
nodeType: 'host',
type: el.type,
props: el._store.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance.getDOMNode(),
rendered: values(children).map(instanceToTree),
Expand All @@ -86,7 +86,7 @@ function instanceToTree(inst) {
nodeType: 'class',
type: el.type,
props: el._store.props,
key: el.key,
key: el.key || undefined,
ref: el.ref,
instance: inst._instance || inst._hostNode || null,
rendered: instanceToTree(inst._renderedComponent),
Expand Down Expand Up @@ -174,7 +174,7 @@ class ReactThirteenAdapter extends EnzymeAdapter {
nodeType: 'class',
type: cachedNode.type,
props: cachedNode.props,
key: cachedNode.key,
key: cachedNode.key || undefined,
ref: cachedNode.ref,
instance: renderer._instance._instance,
rendered: elementToTree(output),
Expand Down
Loading

0 comments on commit c26a615

Please sign in to comment.