Skip to content

Commit d591115

Browse files
MichaelDeBoeywombleton
authored andcommitted
feat(eslint-config-react-app): Add jest & testing-library rules (facebook#8963)
1 parent d4e2590 commit d591115

File tree

6 files changed

+36
-12
lines changed

6 files changed

+36
-12
lines changed

Diff for: packages/eslint-config-react-app/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This config also ships with optional Jest rules for ESLint (based on [`eslint-pl
3939
You'll first need to add the ESLint plugin for Jest (if you don't already have it installed).
4040

4141
```sh
42-
npm install --save-dev eslint-plugin-jest@^24.0.0
42+
npm install --save-dev eslint-plugin-jest@^24.0.0 eslint-plugin-testing-library&^3.9.0
4343
```
4444

4545
You can then enable these rules by adding the Jest config to the `extends` array in your ESLint config.

Diff for: packages/eslint-config-react-app/jest.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,34 @@
1212
// and we try not to use "ERROR" level at all.
1313

1414
module.exports = {
15-
plugins: ['jest'],
15+
plugins: ['jest', 'testing-library'],
1616
overrides: [
1717
{
1818
files: ['**/__tests__/**/*', '**/*.{spec,test}.*'],
1919
env: {
2020
'jest/globals': true,
2121
},
2222
// A subset of the recommended rules:
23-
// https://github.com/jest-community/eslint-plugin-jest#rules
2423
rules: {
25-
'jest/expect-expect': 'warn',
26-
'jest/no-identical-title': 'warn',
27-
'jest/valid-describe': 'warn',
28-
'jest/valid-expect': 'warn',
29-
'jest/valid-expect-in-promise': 'warn',
24+
// https://github.com/jest-community/eslint-plugin-jest
25+
'jest/no-conditional-expect': 'error',
26+
'jest/no-identical-title': 'error',
27+
'jest/no-interpolation-in-snapshots': 'error',
28+
'jest/no-jasmine-globals': 'error',
29+
'jest/no-jest-import': 'error',
30+
'jest/no-mocks-import': 'error',
31+
'jest/valid-describe': 'error',
32+
'jest/valid-expect': 'error',
33+
'jest/valid-expect-in-promise': 'error',
34+
'jest/valid-title': 'warn',
35+
36+
// https://github.com/testing-library/eslint-plugin-testing-library
37+
'testing-library/await-async-query': 'error',
38+
'testing-library/await-async-utils': 'error',
39+
'testing-library/no-await-sync-query': 'warn',
40+
'testing-library/no-dom-import': ['error', 'react'],
41+
'testing-library/no-wait-for-empty-callback': 'error',
42+
'testing-library/no-wait-for-snapshot': 'error',
3043
},
3144
},
3245
],

Diff for: packages/eslint-config-react-app/package.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@
2626
"eslint-plugin-jest": "^24.0.0",
2727
"eslint-plugin-jsx-a11y": "^6.3.1",
2828
"eslint-plugin-react": "^7.20.3",
29-
"eslint-plugin-react-hooks": "^4.0.8"
29+
"eslint-plugin-react-hooks": "^4.0.8",
30+
"eslint-plugin-testing-library": "^3.9.0"
31+
},
32+
"peerDependenciesMeta": {
33+
"eslint-plugin-jest": {
34+
"optional": true
35+
},
36+
"eslint-plugin-testing-library": {
37+
"optional": true
38+
}
3039
},
3140
"peerDependenciesMeta": {
3241
"eslint-plugin-jest": {

Diff for: packages/react-error-overlay/.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "react-app",
2+
"extends": ["react-app", "react-app/jest"],
33
"rules": {
44
"curly": "warn"
55
}

Diff for: packages/react-error-overlay/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@
4848
"eslint-config-react-app": "^5.2.1",
4949
"eslint-plugin-flowtype": "^5.2.0",
5050
"eslint-plugin-import": "^2.22.0",
51-
"eslint-plugin-jest": "^24.0.1",
51+
"eslint-plugin-jest": "^24.1.0",
5252
"eslint-plugin-jsx-a11y": "^6.3.1",
5353
"eslint-plugin-react": "^7.20.6",
5454
"eslint-plugin-react-hooks": "^4.1.2",
55+
"eslint-plugin-testing-library": "^3.9.2",
5556
"flow-bin": "^0.116.0",
5657
"html-entities": "1.3.1",
5758
"jest": "26.4.2",

Diff for: packages/react-scripts/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@
4848
"eslint-config-react-app": "^5.2.1",
4949
"eslint-plugin-flowtype": "^5.2.0",
5050
"eslint-plugin-import": "^2.22.0",
51-
"eslint-plugin-jest": "^24.0.1",
51+
"eslint-plugin-jest": "^24.1.0",
5252
"eslint-plugin-jsx-a11y": "^6.3.1",
5353
"eslint-plugin-react": "^7.20.6",
5454
"eslint-plugin-react-hooks": "^4.1.2",
55+
"eslint-plugin-testing-library": "^3.9.2",
5556
"eslint-webpack-plugin": "^2.1.0",
5657
"file-loader": "6.1.0",
5758
"fs-extra": "^9.0.0",

0 commit comments

Comments
 (0)