Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Gołąb authored Oct 21, 2017
2 parents 85e4ea0 + e798b18 commit 43fcb5b
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 90 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 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
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
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
6 changes: 0 additions & 6 deletions docs/installation/react-014.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@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: 0 additions & 6 deletions docs/installation/react-15.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@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
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
16 changes: 10 additions & 6 deletions packages/enzyme-adapter-react-14/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"name": "enzyme-adapter-react-14",
"version": "1.0.1",
"version": "1.0.2",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
"scripts": {
"clean": "rimraf build",
"lint": "eslint --ext js,jsx src test",
"lint": "eslint --ext js,jsx .",
"pretest": "npm run lint",
"prebuild": "npm run clean",
"build": "babel src --out-dir build",
"watch": "babel src --out-dir build -w"
"watch": "npm run build -- -w",
"prepublish": "npm run build && safe-publish-latest"
},
"repository": {
"type": "git",
Expand All @@ -35,19 +38,20 @@
"lodash": "^4.17.4",
"object.assign": "^4.0.4",
"object.values": "^1.0.4",
"prop-types": "^15.5.10"
"prop-types": "^15.5.10",
"react-addons-test-utils": "^0.14.0"
},
"peerDependencies": {
"enzyme": "^3.0.0",
"react": "^0.14.0",
"react-addons-test-utils": "^0.14.0",
"react-dom": "^0.14.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"enzyme": "^3.0.0",
"eslint": "^4.4.1",
"in-publish": "^2.0.0",
"rimraf": "^2.6.1"
"rimraf": "^2.6.1",
"safe-publish-latest": "^1.1.1"
}
}
16 changes: 10 additions & 6 deletions packages/enzyme-adapter-react-15.4/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"name": "enzyme-adapter-react-15.4",
"version": "1.0.1",
"version": "1.0.2",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
"scripts": {
"clean": "rimraf build",
"lint": "eslint --ext js,jsx src test",
"lint": "eslint --ext js,jsx .",
"pretest": "npm run lint",
"prebuild": "npm run clean",
"build": "babel src --out-dir build",
"watch": "babel src --out-dir build -w"
"watch": "npm run build -- -w",
"prepublish": "npm run build && safe-publish-latest"
},
"repository": {
"type": "git",
Expand All @@ -35,19 +38,20 @@
"lodash": "^4.17.4",
"object.assign": "^4.0.4",
"object.values": "^1.0.4",
"prop-types": "^15.5.10"
"prop-types": "^15.5.10",
"react-addons-test-utils": "15.0.0-0 - 15.4.x"
},
"peerDependencies": {
"enzyme": "^3.0.0",
"react": "15.0.0-0 - 15.4.x",
"react-addons-test-utils": "15.0.0-0 - 15.4.x",
"react-dom": "15.0.0-0 - 15.4.x"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"enzyme": "^3.0.0",
"eslint": "^4.4.1",
"in-publish": "^2.0.0",
"rimraf": "^2.6.1"
"rimraf": "^2.6.1",
"safe-publish-latest": "^1.1.1"
}
}
18 changes: 11 additions & 7 deletions packages/enzyme-adapter-react-15/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"name": "enzyme-adapter-react-15",
"version": "1.0.1",
"version": "1.0.2",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
"scripts": {
"clean": "rimraf build",
"lint": "eslint --ext js,jsx src test",
"lint": "eslint --ext js,jsx .",
"pretest": "npm run lint",
"prebuild": "npm run clean",
"build": "babel src --out-dir build",
"watch": "babel src --out-dir build -w"
"watch": "npm run build -- -w",
"prepublish": "npm run build && safe-publish-latest"
},
"repository": {
"type": "git",
Expand All @@ -35,19 +38,20 @@
"lodash": "^4.17.4",
"object.assign": "^4.0.4",
"object.values": "^1.0.4",
"prop-types": "^15.5.10"
"prop-types": "^15.5.10",
"react-test-renderer": "^15.5.0"
},
"peerDependencies": {
"enzyme": "^3.0.0",
"react": "^15.5.0",
"react-dom": "^15.5.0",
"react-test-renderer": "^15.5.0"
"react-dom": "^15.5.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"enzyme": "^3.0.0",
"eslint": "^4.4.1",
"in-publish": "^2.0.0",
"rimraf": "^2.6.1"
"rimraf": "^2.6.1",
"safe-publish-latest": "^1.1.1"
}
}
18 changes: 11 additions & 7 deletions packages/enzyme-adapter-react-16/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"name": "enzyme-adapter-react-16",
"version": "1.0.1",
"version": "1.0.2",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
"scripts": {
"clean": "rimraf build",
"lint": "eslint --ext js,jsx src test",
"lint": "eslint --ext js,jsx .",
"pretest": "npm run lint",
"prebuild": "npm run clean",
"build": "babel src --out-dir build",
"watch": "babel src --out-dir build -w"
"watch": "npm run build -- -w",
"prepublish": "npm run build && safe-publish-latest"
},
"repository": {
"type": "git",
Expand All @@ -35,19 +38,20 @@
"lodash": "^4.17.4",
"object.assign": "^4.0.4",
"object.values": "^1.0.4",
"prop-types": "^15.5.10"
"prop-types": "^15.5.10",
"react-test-renderer": "^16.0.0-0"
},
"peerDependencies": {
"enzyme": "^3.0.0",
"react": "^16.0.0-0",
"react-dom": "^16.0.0-0",
"react-test-renderer": "^16.0.0-0"
"react-dom": "^16.0.0-0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"enzyme": "^3.0.0",
"eslint": "^4.4.1",
"in-publish": "^2.0.0",
"rimraf": "^2.6.1"
"rimraf": "^2.6.1",
"safe-publish-latest": "^1.1.1"
}
}
Loading

0 comments on commit 43fcb5b

Please sign in to comment.