All files / src/rules jest.ts

100% Statements 1/1
100% Branches 0/0
100% Functions 0/0
100% Lines 1/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128            1x                                                                                                                                                                                                                                                  
/* eslint-env commonjs */
 
/* eslint-disable import/unambiguous */
/* eslint-disable import/no-commonjs */
/* eslint-disable sort-keys */
 
module.exports = {
  plugins: ['jest'],
  rules: {
    // Enforce consistent test or it keyword
    'jest/consistent-test-it': ['error', { fn: 'test' }],
 
    // Enforce assertion to be made in a test body
    'jest/expect-expect': 'error',
 
    // Disallow capitalized test names
    'jest/lowercase-name': 'error',
 
    // Disallow alias methods
    'jest/no-alias-methods': 'error',
 
    // Disallow disabled tests
    'jest/no-disabled-tests': 'error',
 
    // Disallow commented out tests
    'jest/no-commented-out-tests': 'error',
 
    // Prevent calling expect conditionally
    'jest/no-conditional-expect': 'error',
 
    // Disallow use of deprecated functions
    'jest/no-deprecated-functions': 'error',
 
    // Disallow duplicate hooks withing a describe block
    'jest/no-duplicate-hooks': 'error',
 
    // Prevent exporting from test files
    'jest/no-export': 'error',
 
    // Disallow focused tests
    'jest/no-focused-tests': 'error',
 
    // Disallow setup and teardown hooks
    'jest/no-hooks': 'off',
 
    // Disallow identical titles
    'jest/no-identical-title': 'error',
 
    // Disallow conditional logic
    'jest/no-if': 'error',
 
    // Disallow Jasmine globals
    'jest/no-jasmine-globals': 'error',
 
    // Disallow importing jest
    'jest/no-jest-import': 'error',
 
    // Disallow manually importing from __mocks__
    'jest/no-mocks-import': 'error',
 
    // Disallow specific matchers & modifiers
    'jest/no-restricted-matchers': 'error',
 
    // Prevents expects that are outside of an it or test block.
    'jest/no-standalone-expect': 'error',
 
    // Disallow large snapshots
    'jest/no-large-snapshots': 'off',
 
    // Using a callback in asynchronous tests
    'jest/no-test-callback': 'error',
 
    // Disallow using f & x prefixes to define focused/skipped tests
    'jest/no-test-prefixes': 'error',
 
    // Disallow explicitly returning from tests
    'jest/no-test-return-statement': 'error',
 
    // Suggest using expect.assertions() OR expect.hasAssertions()
    'jest/prefer-expect-assertions': 'error',
 
    // Suggest to have all hooks at top level
    'jest/prefer-hooks-on-top': 'error',
 
    // Suggest using jest.spyOn()
    'jest/prefer-spy-on': 'error',
 
    // Suggest using toStrictEqual()
    'jest/prefer-strict-equal': 'error',
 
    // Suggest using toBeNull()
    'jest/prefer-to-be-null': 'error',
 
    // Suggest using toBeUndefined()
    'jest/prefer-to-be-undefined': 'error',
 
    // Suggest using toContain()
    'jest/prefer-to-contain': 'error',
 
    // Suggest using toHaveLength()
    'jest/prefer-to-have-length': 'error',
 
    // Enforce valid describe() callback
    'jest/valid-describe': 'error',
 
    // Enforce having return statement when testing with promises
    'jest/valid-expect-in-promise': 'error',
 
    // Enforce valid expect() usage
    'jest/valid-expect': 'error',
 
    // Suggest using test.todo()
    'jest/prefer-todo': 'error',
 
    // Require a message for toThrow()
    'jest/require-to-throw-message': 'error',
 
    // Prevents test cases and hooks to be outside of a describe block
    'jest/require-top-level-describe': 'error',
 
    // Suggest using toBeCalledWith() OR toHaveBeenCalledWith()
    'jest/prefer-called-with': 'error',
 
    // Enforce valid titles
    'jest/valid-title': 'error',
  },
}