Skip to content

Commit

Permalink
[*] [Dev Deps] update babel-core, `babel-plugin-transform-replace-o…
Browse files Browse the repository at this point in the history
…bject-assign`, `babel-preset-airbnb`, `eslint`, `eslint-config-airbnb`, `eslint-plugin-import`, `eslint-plugin-jsx-a11y`, `eslint-plugin-react`, `lerna`, `prop-types`
  • Loading branch information
ljharb committed Jul 7, 2018
1 parent edabb1b commit 0c8e630
Show file tree
Hide file tree
Showing 62 changed files with 450 additions and 231 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"presets": ["airbnb"],
"plugins": [
["transform-replace-object-assign", "object.assign"],
["transform-replace-object-assign", { "moduleSpecifier": "object.assign" }],
],
ignore: [
"packages/enzyme-test-suite/test/_helpers/untranspiled*",
Expand Down
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"mocha": true
},
"rules": {
"react/jsx-one-expression-per-line": 0, // TODO: re-enable once fixed
"id-length": 0,
"new-cap": [2, { "capIsNewExceptions": ["AND"] }],
"react/jsx-pascal-case": [2, { "allowAllCaps": true }],
Expand Down
2 changes: 2 additions & 0 deletions docs/api/ReactWrapper/matchesElement.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class MyComponent extends React.Component {
super(props);
this.handleClick = this.handleClick.bind(this);
}

handleClick() {
/* ... */
}

render() {
return (
<button type="button" onClick={this.handleClick} className="foo bar">Hello</button>
Expand Down
1 change: 1 addition & 0 deletions docs/api/ReactWrapper/mount.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Foo extends React.Component {
this.componentWillMount = willMount;
this.componentDidMount = didMount;
}

render() {
const { id } = this.props;
return (
Expand Down
3 changes: 2 additions & 1 deletion docs/api/ReactWrapper/setContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import React from 'react';
import PropTypes from 'prop-types';

function SimpleComponent(props, context) {
return <div>{context.name}</div>;
const { name } = context;
return <div>{name}</div>;
}
SimpleComponent.contextTypes = {
name: PropTypes.string,
Expand Down
3 changes: 2 additions & 1 deletion docs/api/ReactWrapper/setProps.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ NOTE: can only be called on a wrapper instance that is also the root instance.
#### Example

```jsx
import React from 'react';
import PropTypes from 'prop-types';

function Foo({ name }) {
return (
<div className={this.props.name} />
<div className={name} />
);
}
Foo.propTypes = {
Expand Down
4 changes: 3 additions & 1 deletion docs/api/ReactWrapper/setState.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ class Foo extends React.Component {
super(props);
this.state = { name: 'foo' };
}

render() {
const { name } = this.state;
return (
<div className={this.state.name} />
<div className={name} />
);
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/api/ReactWrapper/simulate.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Foo extends React.Component {
super(props);
this.state = { count: 0 };
}

render() {
const { count } = this.state;
return (
Expand Down
36 changes: 31 additions & 5 deletions docs/api/ReactWrapper/type.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
# `.type() => String|Function`
# `.type() => String|Function|null`

Returns the type of the current node of this wrapper. If it's a composite component, this will be
the component constructor. If it's a native DOM node, it will be a string of the tag name.
the component constructor. If it's a native DOM node, it will be a string of the tag name. If it's `null`, it will be `null`.

Note: can only be called on a wrapper of a single node.


#### Returns

`String|Function`: The type of the current node
`String|Function|null`: The type of the current node



#### Examples

```jsx
const wrapper = mount(<div />);
function Foo() {
return <div />;
}
const wrapper = mount(<Foo />);
expect(wrapper.type()).to.equal('div');
```

```jsx
function Foo() {
return (
<div>
<button type="button" className="btn">Button</button>
</div>
);
}
const wrapper = mount(<Foo />);
expect(wrapper.find('.btn').type()).to.equal('button');
```

```jsx
function Foo() {
return <Bar />;
}
const wrapper = mount(<Foo />);
expect(wrapper.type()).to.equal(Foo);
expect(wrapper.type()).to.equal(Bar);
```

```jsx
function Null() {
return null;
}
const wrapper = mount(<Null />);
expect(wrapper.type()).to.equal(null);
```
1 change: 1 addition & 0 deletions docs/api/ReactWrapper/unmount.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Foo extends React.Component {
this.componentWillMount = willMount;
this.componentDidMount = didMount;
}

render() {
const { id } = this.props;
return (
Expand Down
1 change: 1 addition & 0 deletions docs/api/ReactWrapper/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ImpureRender extends React.Component {
super(props);
this.count = 0;
}

render() {
this.count += 1;
return <div>{this.count}</div>;
Expand Down
2 changes: 2 additions & 0 deletions docs/api/ShallowWrapper/matchesElement.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class MyComponent extends React.Component {
super(props);
this.handleClick = this.handleClick.bind(this);
}

handleClick() {
// ...
}

render() {
return (
<button type="button" onClick={this.handleClick} className="foo bar">Hello</button>
Expand Down
1 change: 1 addition & 0 deletions docs/api/ShallowWrapper/setContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ NOTE: can only be called on a wrapper instance that is also the root instance.
#### Example

```jsx
import React from 'react';
import PropTypes from 'prop-types';

function SimpleComponent(props, context) {
Expand Down
1 change: 1 addition & 0 deletions docs/api/ShallowWrapper/setProps.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ NOTE: can only be called on a wrapper instance that is also the root instance.
#### Example

```jsx
import React from 'react';
import PropTypes from 'prop-types';

function Foo({ name }) {
Expand Down
1 change: 1 addition & 0 deletions docs/api/ShallowWrapper/setState.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Foo extends React.Component {
super(props);
this.state = { name: 'foo' };
}

render() {
const { name } = this.state;
return (
Expand Down
1 change: 1 addition & 0 deletions docs/api/ShallowWrapper/simulate.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Foo extends React.Component {
super(props);
this.state = { count: 0 };
}

render() {
const { count } = this.state;
return (
Expand Down
2 changes: 1 addition & 1 deletion docs/api/ShallowWrapper/type.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ expect(wrapper.type()).to.equal('div');
function Foo() {
return (
<div>
<button className="btn">Button</button>
<button type="button" className="btn">Button</button>
</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions docs/api/ShallowWrapper/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ImpureRender extends React.Component {
super(props);
this.count = 0;
}

render() {
this.count += 1;
return <div>{this.count}</div>;
Expand Down
32 changes: 22 additions & 10 deletions docs/guides/migration-from-2-to-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ example the following react components:
```js
class Box extends React.Component {
render() {
return <div className="box">{this.props.children}</div>;
const { children } = this.props;
return <div className="box">{children}</div>;
}
}

class Foo extends React.Component {
render() {
return (
Expand Down Expand Up @@ -158,7 +160,7 @@ we would like to introduce.

## `find()` now returns host nodes and DOM nodes

In some cases find will return a host node and DOM node. Take the following for example:
In some cases find will return a host node and DOM node. Take the following for example:

```
const Foo = () => <div/>;
Expand All @@ -173,7 +175,7 @@ console.log(wrapper.find('.bar').length); // 2

Since `<Foo/>` has the className `bar` it is returned as the _hostNode_. As expected the `<div>` with the className `bar` is also returned

To avoid this you can explicity query for the DOM node: `wrapper.find('div.bar')`. Alternatively if you would like to only find host nodes use [hostNodes()](http://airbnb.io/enzyme/docs/api/ShallowWrapper/hostNodes.md#hostnodes--shallowwrapper)
To avoid this you can explicity query for the DOM node: `wrapper.find('div.bar')`. Alternatively if you would like to only find host nodes use [hostNodes()](http://airbnb.io/enzyme/docs/api/ShallowWrapper/hostNodes.md#hostnodes--shallowwrapper)

## For `mount`, updates are sometimes required when they weren't before

Expand All @@ -193,18 +195,23 @@ class CurrentTime extends React.Component {
now: Date.now(),
};
}

componentDidMount() {
this.tick();
}

componentWillUnmount() {
clearTimeout(this.timer);
}

tick() {
this.setState({ now: Date.now() });
this.timer = setTimeout(tick, 0);
}

render() {
return <span>{this.state.now}</span>;
const { now } = this.state;
return <span>{now}</span>;
}
}
```
Expand Down Expand Up @@ -235,18 +242,22 @@ class Counter extends React.Component {
this.increment = this.increment.bind(this);
this.decrement = this.decrement.bind(this);
}

increment() {
this.setState({ count: this.state.count + 1 });
this.setState(({ count }) => ({ count: count + 1 }));
}

decrement() {
this.setState({ count: this.state.count - 1 });
this.setState(({ count }) => ({ count: count - 1 }));
}

render() {
const { count } = this.state;
return (
<div>
<div className="count">Count: {this.state.count}</div>
<button className="inc" onClick={this.increment}>Increment</button>
<button className="dec" onClick={this.decrement}>Decrement</button>
<div className="count">Count: {count}</div>
<button type="button" className="inc" onClick={this.increment}>Increment</button>
<button type="button" className="dec" onClick={this.decrement}>Decrement</button>
</div>
);
}
Expand Down Expand Up @@ -500,7 +511,8 @@ equivalent to the absence of a prop. Consider the following example:
```js
class Foo extends React.Component {
render() {
return <div className={this.props.foo} id={this.props.bar} />;
const { foo, bar } = this.props;
return <div className={foo} id={bar} />;
}
}
```
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-core": "^6.26.3",
"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-plugin-transform-replace-object-assign": "^1.0.0",
"babel-preset-airbnb": "^2.5.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"coveralls": "^2.13.3",
"eslint": "^4.18.2",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jsx-a11y": "^6.1.0",
"eslint-plugin-markdown": "^1.0.0-beta.7",
"eslint-plugin-react": "^7.7.0",
"eslint-plugin-react": "^7.10.0",
"gitbook-cli": "^1.0.1",
"gitbook-plugin-anchors": "^0.7.1",
"gitbook-plugin-codeblock-disable-glossary": "0.0.1",
Expand All @@ -94,9 +94,9 @@
"karma-mocha": "^1.3.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.1",
"lerna": "^2.5.1",
"lerna": "^2.11.0",
"mocha": "^3.5.0",
"prop-types": "^15.6.1",
"prop-types": "^15.6.2",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.1",
"webpack": "^1.15.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-adapter-react-13/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": ["airbnb"],
"plugins": [
["transform-replace-object-assign", "object.assign"],
["transform-replace-object-assign", { "moduleSpecifier": "object.assign" }],
],
}
22 changes: 14 additions & 8 deletions packages/enzyme-adapter-react-13/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
"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 Down Expand Up @@ -43,13 +46,16 @@
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-transform-replace-object-assign": "^1.0.0",
"babel-preset-airbnb": "^2.5.1",
"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",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jsx-a11y": "^6.1.0",
"eslint-plugin-react": "^7.10.0",
"in-publish": "^2.0.0",
"rimraf": "^2.6.2"
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.1"
}
}

0 comments on commit 0c8e630

Please sign in to comment.