Skip to content

Commit aa9d2a9

Browse files
committed
Add eslint-plugin-jest
1 parent 54c5a52 commit aa9d2a9

File tree

8 files changed

+90
-80
lines changed

8 files changed

+90
-80
lines changed

.eslintrc.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,19 @@ const config = {
55
parser: '@typescript-eslint/parser',
66
parserOptions: {},
77
extends: [
8-
// /!\ Order seems to matter
9-
8+
// /!\ Order matters: the next one overrides rules from the previous one
9+
'plugin:jest/recommended',
1010
'airbnb',
11+
// Already done by Airbnb
12+
//'plugin:react/recommended'
1113
'plugin:@typescript-eslint/recommended',
1214
'plugin:prettier/recommended',
1315
'prettier/@typescript-eslint',
1416
'prettier/react'
15-
16-
// Already done by Airbnb
17-
//'plugin:react/recommended'
1817
],
19-
plugins: ['@typescript-eslint', 'react', 'react-hooks'],
20-
settings: {
21-
react: {
22-
version: 'detect'
23-
}
24-
},
18+
plugins: ['react-hooks'],
2519
env: {
26-
es6: true,
27-
browser: true,
28-
node: true,
29-
jest: true
20+
browser: true
3021
},
3122
globals: {
3223
// Jest Puppeteer, see https://github.com/smooth-code/jest-puppeteer/blob/v4.0.0/README.md#configure-eslint
@@ -50,6 +41,7 @@ const config = {
5041

5142
'import/no-extraneous-dependencies': 'off',
5243
'import/no-unresolved': 'off',
44+
// [Avoid Export Default](https://basarat.gitbook.io/typescript/main-1/defaultisbad)
5345
'import/prefer-default-export': 'off',
5446
'import/extensions': 'off',
5547

@@ -61,34 +53,30 @@ const config = {
6153
'no-shadow': 'off',
6254
'@typescript-eslint/no-shadow': 'error',
6355

64-
'@typescript-eslint/indent': 'off',
6556
'@typescript-eslint/explicit-function-return-type': 'off',
6657
'@typescript-eslint/no-non-null-assertion': 'off',
6758
'@typescript-eslint/camelcase': 'off',
6859
'@typescript-eslint/no-unused-vars': 'off',
6960
'@typescript-eslint/no-empty-interface': 'off',
70-
'@typescript-eslint/explicit-member-accessibility': 'off',
7161
'@typescript-eslint/no-explicit-any': 'off',
7262
'@typescript-eslint/ban-ts-comment': 'off',
73-
'@typescript-eslint/no-parameter-properties': 'off',
74-
'@typescript-eslint/array-type': 'off',
7563
'@typescript-eslint/ban-ts-ignore': 'off',
7664
'@typescript-eslint/explicit-module-boundary-types': 'off',
7765

78-
'jsx-a11y/label-has-for': 'off',
7966
'jsx-a11y/label-has-associated-control': 'off',
80-
'jsx-a11y/iframe-has-title': 'off',
8167

8268
'react/no-unescaped-entities': 'off',
8369
'react/jsx-filename-extension': ['error', { extensions: ['.tsx', '.jsx'] }],
8470
'react/jsx-pascal-case': 'off',
8571
'react/jsx-props-no-spreading': 'off',
86-
'react/static-property-placement': ['error', 'static public field'],
87-
'react/state-in-constructor': ['error', 'never'],
88-
'react/sort-comp': 'off',
72+
'react/static-property-placement': 'off',
73+
'react/state-in-constructor': 'off',
8974

9075
'react-hooks/rules-of-hooks': 'error',
91-
'react-hooks/exhaustive-deps': 'warn'
76+
'react-hooks/exhaustive-deps': 'error',
77+
78+
'jest/no-expect-resolves': 'error',
79+
'jest/expect-expect': 'off'
9280
},
9381

9482
// FIXME ?
@@ -106,6 +94,12 @@ const config = {
10694
rules: {
10795
'react/require-default-props': 'off'
10896
}
97+
},
98+
{
99+
files: ['*.test.tsx'],
100+
rules: {
101+
'jsx-a11y/iframe-has-title': 'off'
102+
}
109103
}
110104
]
111105
};

examples/Bootstrap4/App.test.e2e.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ test('john/123456/12345', async () => {
2020
//const usernameFeedbacks = await page.$$('input[name=username] ~ span[data-feedback]');
2121
const usernameFeedbacks = await username.$x('./following-sibling::span[@data-feedback]');
2222
expect(usernameFeedbacks).toHaveLength(1);
23-
await expect(usernameFeedbacks[0]).toMatch('Username already taken, choose another');
23+
expect(usernameFeedbacks[0]).toMatch('Username already taken, choose another');
2424

2525
const password = await page.$('input[name=password]');
2626
await password.click();
2727
await password.type('123456');
2828
await page.waitForSelector('input[name=password] ~ span[data-feedback]');
2929
const passwordFeedbacks = await page.$$('input[name=password] ~ span[data-feedback]');
3030
expect(passwordFeedbacks).toHaveLength(4);
31-
await expect(passwordFeedbacks[0]).toMatch('Should contain small letters');
32-
await expect(passwordFeedbacks[1]).toMatch('Should contain capital letters');
33-
await expect(passwordFeedbacks[2]).toMatch('Should contain special characters');
34-
await expect(passwordFeedbacks[3]).toMatch('Looks good!');
31+
expect(passwordFeedbacks[0]).toMatch('Should contain small letters');
32+
expect(passwordFeedbacks[1]).toMatch('Should contain capital letters');
33+
expect(passwordFeedbacks[2]).toMatch('Should contain special characters');
34+
expect(passwordFeedbacks[3]).toMatch('Looks good!');
3535

3636
const passwordConfirm = await page.$('input[name=passwordConfirm]');
3737
await passwordConfirm.click();
@@ -40,7 +40,7 @@ test('john/123456/12345', async () => {
4040
'input[name=passwordConfirm] ~ span[data-feedback]'
4141
);
4242
expect(passwordConfirmFeedbacks).toHaveLength(1);
43-
await expect(passwordConfirmFeedbacks[0]).toMatch('Not the same password');
43+
expect(passwordConfirmFeedbacks[0]).toMatch('Not the same password');
4444

4545
const signUp = (await page.$x("//button[text() = 'Sign Up']"))[0];
4646
// [Get Custom Attribute value](https://github.com/GoogleChrome/puppeteer/issues/1451)
@@ -56,19 +56,19 @@ test('jimmy/12345/12345', async () => {
5656
//const usernameFeedbacks = await page.$$('input[name=username] ~ span[data-feedback]');
5757
const usernameFeedbacks = await username.$x('./following-sibling::span[@data-feedback]');
5858
expect(usernameFeedbacks).toHaveLength(2);
59-
await expect(usernameFeedbacks[0]).toMatch('Username available');
60-
await expect(usernameFeedbacks[1]).toMatch('Looks good!');
59+
expect(usernameFeedbacks[0]).toMatch('Username available');
60+
expect(usernameFeedbacks[1]).toMatch('Looks good!');
6161

6262
const password = await page.$('input[name=password]');
6363
await password.click();
6464
await password.type('12345');
6565
await page.waitForSelector('input[name=password] ~ span[data-feedback]');
6666
const passwordFeedbacks = await page.$$('input[name=password] ~ span[data-feedback]');
6767
expect(passwordFeedbacks).toHaveLength(4);
68-
await expect(passwordFeedbacks[0]).toMatch('Should contain small letters');
69-
await expect(passwordFeedbacks[1]).toMatch('Should contain capital letters');
70-
await expect(passwordFeedbacks[2]).toMatch('Should contain special characters');
71-
await expect(passwordFeedbacks[3]).toMatch('Looks good!');
68+
expect(passwordFeedbacks[0]).toMatch('Should contain small letters');
69+
expect(passwordFeedbacks[1]).toMatch('Should contain capital letters');
70+
expect(passwordFeedbacks[2]).toMatch('Should contain special characters');
71+
expect(passwordFeedbacks[3]).toMatch('Looks good!');
7272

7373
const passwordConfirm = await page.$('input[name=passwordConfirm]');
7474
await passwordConfirm.click();
@@ -77,7 +77,7 @@ test('jimmy/12345/12345', async () => {
7777
'input[name=passwordConfirm] ~ span[data-feedback]'
7878
);
7979
expect(passwordConfirmFeedbacks).toHaveLength(1);
80-
await expect(passwordConfirmFeedbacks[0]).toMatch('Looks good!');
80+
expect(passwordConfirmFeedbacks[0]).toMatch('Looks good!');
8181

8282
const signUp = (await page.$x("//button[text() = 'Sign Up']"))[0];
8383
// [Get Custom Attribute value](https://github.com/GoogleChrome/puppeteer/issues/1451)

examples/Password/App.test.e2e.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ test('john@beatles/123456/12345', async () => {
1919
//const emailFeedbacks = await page.$$('input[name=email] ~ span[data-feedback]');
2020
const emailFeedbacks = await email.$x('./following-sibling::span[@data-feedback]');
2121
expect(emailFeedbacks).toHaveLength(1);
22-
await expect(emailFeedbacks[0]).toMatch('Looks good!');
22+
expect(emailFeedbacks[0]).toMatch('Looks good!');
2323

2424
const password = (await page.$('input[name=password]'))!;
2525
await password.click();
2626
await password.type('123456');
2727
await page.waitForSelector('input[name=password] ~ span[data-feedback].when-valid');
2828
const passwordFeedbacks = await page.$$('input[name=password] ~ span[data-feedback]');
2929
expect(passwordFeedbacks).toHaveLength(5);
30-
await expect(passwordFeedbacks[0]).toMatch('Should contain small letters');
31-
await expect(passwordFeedbacks[1]).toMatch('Should contain capital letters');
32-
await expect(passwordFeedbacks[2]).toMatch('Should contain special characters');
33-
await expect(passwordFeedbacks[3]).toMatch('This password is very common');
34-
await expect(passwordFeedbacks[4]).toMatch('Looks good!');
30+
expect(passwordFeedbacks[0]).toMatch('Should contain small letters');
31+
expect(passwordFeedbacks[1]).toMatch('Should contain capital letters');
32+
expect(passwordFeedbacks[2]).toMatch('Should contain special characters');
33+
expect(passwordFeedbacks[3]).toMatch('This password is very common');
34+
expect(passwordFeedbacks[4]).toMatch('Looks good!');
3535

3636
const passwordConfirm = (await page.$('input[name=passwordConfirm]'))!;
3737
await passwordConfirm.click();
@@ -40,7 +40,7 @@ test('john@beatles/123456/12345', async () => {
4040
'input[name=passwordConfirm] ~ span[data-feedback]'
4141
);
4242
expect(passwordConfirmFeedbacks).toHaveLength(1);
43-
await expect(passwordConfirmFeedbacks[0]).toMatch('Not the same password');
43+
expect(passwordConfirmFeedbacks[0]).toMatch('Not the same password');
4444

4545
const signUp = (await page.$x("//button[text() = 'Sign Up']"))[0];
4646
// [Get Custom Attribute value](https://github.com/GoogleChrome/puppeteer/issues/1451)
@@ -56,15 +56,15 @@ test('john@beatles/Tr0ub4dor&3/Tr0ub4dor&3', async () => {
5656
//const emailFeedbacks = await page.$$('input[name=email] ~ span[data-feedback]');
5757
const emailFeedbacks = await email.$x('./following-sibling::span[@data-feedback]');
5858
expect(emailFeedbacks).toHaveLength(1);
59-
await expect(emailFeedbacks[0]).toMatch('Looks good!');
59+
expect(emailFeedbacks[0]).toMatch('Looks good!');
6060

6161
const password = (await page.$('input[name=password]'))!;
6262
await password.click();
6363
await password.type('Tr0ub4dor&3');
6464
await page.waitForSelector('input[name=password] ~ span[data-feedback].when-valid');
6565
const passwordFeedbacks = await page.$$('input[name=password] ~ span[data-feedback]');
6666
expect(passwordFeedbacks).toHaveLength(1);
67-
await expect(passwordFeedbacks[0]).toMatch('Looks good!');
67+
expect(passwordFeedbacks[0]).toMatch('Looks good!');
6868

6969
const passwordConfirm = (await page.$('input[name=passwordConfirm]'))!;
7070
await passwordConfirm.click();

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"eslint-config-airbnb": "^18.2.0",
4242
"eslint-config-prettier": "^6.13.0",
4343
"eslint-plugin-import": "^2.22.1",
44+
"eslint-plugin-jest": "^24.1.0",
4445
"eslint-plugin-jsx-a11y": "^6.3.1",
4546
"eslint-plugin-prettier": "^3.1.4",
4647
"eslint-plugin-react": "^7.21.4",

packages/react-form-with-constraints-native/src/Native.test.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,14 @@ describe('FormWithConstraints', () => {
399399

400400
// [async/await toThrow is not working](https://github.com/facebook/jest/issues/1700)
401401

402-
await expect(form.validateFields('username')).resolves.toEqual([
402+
expect(await form.validateFields('username')).toEqual([
403403
{ name: 'username', element: expectTextInput, validations: [] }
404404
]);
405-
await expect(form.validateFields()).rejects.toEqual(
406-
new Error(`Multiple elements matching '[name="password"]' inside the form`)
405+
await expect(form.validateFields()).rejects.toThrow(
406+
`Multiple elements matching '[name="password"]' inside the form`
407407
);
408-
await expect(form.validateFields('password')).rejects.toEqual(
409-
new Error(`Multiple elements matching '[name="password"]' inside the form`)
408+
await expect(form.validateFields('password')).rejects.toThrow(
409+
`Multiple elements matching '[name="password"]' inside the form`
410410
);
411411

412412
wrapper.unmount();
@@ -420,10 +420,10 @@ describe('FormWithConstraints', () => {
420420
);
421421
const form = (wrapper.getInstance() as any) as FormWithConstraints;
422422

423-
await expect(form.validateFields()).resolves.toEqual([]); // Ignore input without FieldFeedbacks
424-
await expect(form.validateFields('username')).resolves.toEqual([]); // Ignore input without FieldFeedbacks
425-
await expect(form.validateFields('unknown')).rejects.toEqual(
426-
new Error(`Could not find field '[name="unknown"]' inside the form`)
423+
expect(await form.validateFields()).toEqual([]); // Ignore input without FieldFeedbacks
424+
expect(await form.validateFields('username')).toEqual([]); // Ignore input without FieldFeedbacks
425+
await expect(form.validateFields('unknown')).rejects.toThrow(
426+
`Could not find field '[name="unknown"]' inside the form`
427427
);
428428

429429
wrapper.unmount();
@@ -435,9 +435,9 @@ describe('FormWithConstraints', () => {
435435
);
436436
const form = (wrapper.getInstance() as any) as FormWithConstraints;
437437

438-
await expect(form.validateFields()).resolves.toEqual([]);
439-
await expect(form.validateFields('unknown')).rejects.toEqual(
440-
new Error(`Could not find field '[name="unknown"]' inside the form`)
438+
expect(await form.validateFields()).toEqual([]);
439+
await expect(form.validateFields('unknown')).rejects.toThrow(
440+
`Could not find field '[name="unknown"]' inside the form`
441441
);
442442

443443
wrapper.unmount();
@@ -659,10 +659,12 @@ describe('FieldFeedback', () => {
659659
</Text>`);
660660
});
661661

662+
// eslint-disable-next-line jest/expect-expect
662663
test('warning', async () => {
663664
//
664665
});
665666

667+
// eslint-disable-next-line jest/expect-expect
666668
test('info', async () => {
667669
//
668670
});
@@ -694,6 +696,7 @@ describe('FieldFeedback', () => {
694696
expect(wrapper.debug()).toEqual('<Text data-feedback="0.0" style={[undefined]} />');
695697
});
696698

699+
// eslint-disable-next-line jest/expect-expect
697700
test('with already existing class', async () => {
698701
//
699702
});
@@ -750,6 +753,7 @@ describe('FieldFeedback', () => {
750753
expect(wrapper.props().style).toEqual({ color: 'red' });
751754
});
752755

756+
// eslint-disable-next-line jest/expect-expect
753757
test('when="valid"', async () => {
754758
// Cannot be implemented properly
755759
});

packages/react-form-with-constraints/src/FieldFeedback.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ describe('validate()', () => {
317317
});
318318
await expect(
319319
fieldFeedbacks_username.emitValidateFieldEvent(input_username_valid)
320-
).rejects.toEqual(new TypeError("Invalid FieldFeedback 'when' type: number"));
320+
).rejects.toThrow("Invalid FieldFeedback 'when' type: number");
321321
});
322322
});
323323

0 commit comments

Comments
 (0)