Skip to content

Commit

Permalink
chore: use property initializer syntax (#8117)
Browse files Browse the repository at this point in the history
  • Loading branch information
peanutenthusiast authored and SimenB committed Mar 14, 2019
1 parent bdeb5af commit 4f06ee4
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
### Chore & Maintenance

- `[*]` Remove flow from code base ([#8061](https://github.com/facebook/jest/pull/8061))
- `[*]` Use property initializer syntax in Jest codebase [#8117](https://github.com/facebook/jest/pull/8117)

### Performance

Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Expand Up @@ -21,6 +21,7 @@ module.exports = {
plugins: [
['@babel/plugin-transform-modules-commonjs', {allowTopLevelThis: true}],
'@babel/plugin-transform-strict-mode',
'@babel/plugin-proposal-class-properties',
],
presets: [
[
Expand Down
Expand Up @@ -15,6 +15,6 @@ PASS __tests__/console.test.js
15 | });
16 |
at BufferedConsole.log (../../packages/jest-console/build/BufferedConsole.js:180:10)
at BufferedConsole.log (../../packages/jest-console/build/BufferedConsole.js:199:10)
at log (__tests__/console.test.js:13:13)
`;
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap
Expand Up @@ -30,6 +30,6 @@ FAIL __tests__/index.js
12 | module.exports = () => 'test';
13 |
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:435:17)
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:455:17)
at Object.require (index.js:10:1)
`;
Expand Up @@ -33,6 +33,6 @@ FAIL __tests__/test.js
| ^
4 |
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:202:17)
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:222:17)
at Object.require (index.js:3:18)
`;
1 change: 1 addition & 0 deletions examples/enzyme/.babelrc.js
Expand Up @@ -2,4 +2,5 @@

module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['@babel/plugin-proposal-class-properties']
};
15 changes: 5 additions & 10 deletions examples/enzyme/CheckboxWithLabel.js
Expand Up @@ -3,18 +3,13 @@
import React from 'react';

export default class CheckboxWithLabel extends React.Component {
constructor(props) {
super(props);
this.state = {isChecked: false};
state = {
isChecked: false,
};

// bind manually because React class components don't auto-bind
// http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding
this.onChange = this.onChange.bind(this);
}

onChange() {
onChange = () => {
this.setState({isChecked: !this.state.isChecked});
}
};

render() {
return (
Expand Down
1 change: 1 addition & 0 deletions examples/enzyme/package.json
Expand Up @@ -8,6 +8,7 @@
},
"devDependencies": {
"@babel/core": "*",
"@babel/plugin-proposal-class-properties": "*",
"@babel/preset-env": "*",
"@babel/preset-react": "*",
"babel-jest": "*",
Expand Down
1 change: 1 addition & 0 deletions examples/react-testing-library/.babelrc.js
Expand Up @@ -2,4 +2,5 @@

module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['@babel/plugin-proposal-class-properties']
};
13 changes: 3 additions & 10 deletions examples/react-testing-library/CheckboxWithLabel.js
Expand Up @@ -3,18 +3,11 @@
import React from 'react';

export default class CheckboxWithLabel extends React.Component {
constructor(props) {
super(props);
this.state = {isChecked: false};
state = {isChecked: false};

// bind manually because React class components don't auto-bind
// http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding
this.onChange = this.onChange.bind(this);
}

onChange() {
onChange = () => {
this.setState({isChecked: !this.state.isChecked});
}
};

render() {
return (
Expand Down
1 change: 1 addition & 0 deletions examples/react-testing-library/package.json
Expand Up @@ -8,6 +8,7 @@
},
"devDependencies": {
"@babel/core": "*",
"@babel/plugin-proposal-class-properties": "*",
"@babel/preset-env": "*",
"@babel/preset-react": "*",
"babel-jest": "*",
Expand Down
8 changes: 2 additions & 6 deletions examples/react/CheckboxWithLabel.js
Expand Up @@ -6,15 +6,11 @@ export default class CheckboxWithLabel extends React.Component {
constructor(props) {
super(props);
this.state = {isChecked: false};

// bind manually because React class components don't auto-bind
// http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding
this.onChange = this.onChange.bind(this);
}

onChange() {
onChange = () => {
this.setState({isChecked: !this.state.isChecked});
}
};

render() {
return (
Expand Down
11 changes: 4 additions & 7 deletions examples/snapshot/Link.react.js
Expand Up @@ -11,21 +11,18 @@ export default class Link extends React.Component {
constructor() {
super();

this._onMouseEnter = this._onMouseEnter.bind(this);
this._onMouseLeave = this._onMouseLeave.bind(this);

this.state = {
class: STATUS.NORMAL,
};
}

_onMouseEnter() {
_onMouseEnter = () => {
this.setState({class: STATUS.HOVERED});
}
};

_onMouseLeave() {
_onMouseLeave = () => {
this.setState({class: STATUS.NORMAL});
}
};

render() {
return (
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -2,6 +2,7 @@
"private": true,
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-transform-modules-commonjs": "^7.1.0",
"@babel/plugin-transform-strict-mode": "^7.0.0",
"@babel/preset-env": "^7.1.0",
Expand Down
6 changes: 1 addition & 5 deletions packages/jest-core/src/TestSequencer.ts
Expand Up @@ -32,11 +32,7 @@ type Cache = {
* is called to store/update this information on the cache map.
*/
export default class TestSequencer {
private _cache: Map<Context, Cache>;

constructor() {
this._cache = new Map();
}
private _cache: Map<Context, Cache> = new Map();

_getCachePath(context: Context) {
const {config} = context;
Expand Down
15 changes: 5 additions & 10 deletions packages/jest-core/src/plugins/update_snapshots_interactive.ts
Expand Up @@ -11,16 +11,11 @@ import {BaseWatchPlugin, JestHookSubscriber} from 'jest-watcher';
import SnapshotInteractiveMode from '../SnapshotInteractiveMode';

class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin {
private _snapshotInteractiveMode: SnapshotInteractiveMode;
private _failedSnapshotTestAssertions: Array<AssertionLocation>;
isInternal: true;

constructor(options: {stdin: NodeJS.ReadStream; stdout: NodeJS.WriteStream}) {
super(options);
this._failedSnapshotTestAssertions = [];
this._snapshotInteractiveMode = new SnapshotInteractiveMode(this._stdout);
this.isInternal = true;
}
private _snapshotInteractiveMode: SnapshotInteractiveMode = new SnapshotInteractiveMode(
this._stdout,
);
private _failedSnapshotTestAssertions: Array<AssertionLocation> = [];
isInternal: true = true;

getFailedSnapshotTestAssertions(
testResults: AggregatedResult,
Expand Down
6 changes: 2 additions & 4 deletions packages/jest-watcher/src/lib/Prompt.ts
Expand Up @@ -29,13 +29,11 @@ export default class Prompt {
this._onChange = () => {};
this._onSuccess = () => {};
this._onCancel = () => {};

this._onResize = this._onResize.bind(this);
}

private _onResize() {
private _onResize = () => {
this._onChange();
}
};

enter(
onChange: (pattern: string, options: ScrollOptions) => void,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -279,7 +279,7 @@
"@babel/helper-remap-async-to-generator" "^7.1.0"
"@babel/plugin-syntax-async-generators" "^7.2.0"

"@babel/plugin-proposal-class-properties@^7.0.0":
"@babel/plugin-proposal-class-properties@^7.0.0", "@babel/plugin-proposal-class-properties@^7.3.4":
version "7.3.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.3.4.tgz#410f5173b3dc45939f9ab30ca26684d72901405e"
integrity sha512-lUf8D3HLs4yYlAo8zjuneLvfxN7qfKv1Yzbj5vjqaqMJxgJA3Ipwp4VUJ+OrOdz53Wbww6ahwB8UhB2HQyLotA==
Expand Down

0 comments on commit 4f06ee4

Please sign in to comment.