-
Notifications
You must be signed in to change notification settings - Fork 2
/
jest.js
69 lines (67 loc) · 2.17 KB
/
jest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* Generates a config for `jest/no-restricted-matchers` that bans all variations
* of the given base matchers
*
* @param {Record<string, string>} matchers
*
* @return {Record<string, string>}
*/
const banMatchers = matchers => {
return Object.fromEntries(
Object.entries(matchers).flatMap(([matcher, message]) => [
[matcher, message],
[`resolves.${matcher}`, message],
[`resolves.not.${matcher}`, message],
[`rejects.not.${matcher}`, message],
[`not.${matcher}`, message]
])
);
};
/** @type {import('eslint').Linter.Config} */
const config = {
plugins: ['jest', 'jest-formatting'],
extends: [
'plugin:jest/recommended',
'plugin:jest/style',
'plugin:jest-formatting/recommended'
],
rules: {
'@typescript-eslint/unbound-method': 'off',
'jest/consistent-test-it': 'error',
'jest/expect-expect': [
'error',
// todo: TBD - this will need adjusting for react-testing-library
{ assertFunctionNames: ['expect'] }
],
'jest/no-conditional-expect': 'error',
'jest/no-conditional-in-test': 'error',
'jest/no-deprecated-functions': 'error',
'jest/no-large-snapshots': 'warn',
'jest/no-restricted-matchers': [
'error',
banMatchers({
toThrowErrorMatchingSnapshot:
'Use `toThrowErrorMatchingInlineSnapshot()` instead',
toMatchSnapshot: 'Use `toMatchInlineSnapshot()` instead',
toBeTruthy: 'Avoid `toBeTruthy`',
toBeFalsy: 'Avoid `toBeFalsy`'
})
],
'jest/no-test-return-statement': 'error',
'jest/prefer-called-with': 'error',
// you can disable this if you use a `beforeEach` setup script,
'jest/prefer-expect-assertions': 'warn',
'jest/prefer-expect-resolves': 'error',
'jest/prefer-hooks-on-top': 'error',
'jest/prefer-lowercase-title': ['error', { ignoreTopLevelDescribe: true }],
'jest/prefer-spy-on': 'error',
'jest/prefer-strict-equal': 'error',
'jest/prefer-todo': 'error',
'jest/require-hook': 'error',
'jest/require-to-throw-message': 'error',
'jest/require-top-level-describe': 'error',
'jest/unbound-method': 'error',
'jest/valid-title': 'error'
}
};
module.exports = config;