tslint-jest

raw JSON →
1.0.5 verified Fri May 01 auth: no javascript deprecated

tslint-jest is a TSLint plugin providing lint rules for Jest test files. Version 1.0.5 is the latest stable release; the package is no longer actively maintained as TSLint is deprecated in favor of ESLint. It offers rules such as no-alias-methods and expect-expect. Unlike alternatives (eslint-plugin-jest), this plugin is specific to TSLint and is only useful for projects still using TSLint.

error Cannot find module 'tslint-jest'
cause The package is not installed or not in node_modules.
fix
Run npm install --save-dev tslint-jest.
error Invalid rules configuration: unknown rule 'no-alias-methods'
cause tslint-jest extension not added to tslint.json.
fix
Ensure "extends": ["tslint-jest"] is present in tslint.json.
error TypeError: Cannot read property 'apply' of undefined (TSLint error)
cause Incompatible TSLint version or plugin not loaded.
fix
Stick to TSLint 5.x and tslint-jest 1.0.x.
deprecated TSLint is deprecated in favor of ESLint; tslint-jest is no longer maintained.
fix Use eslint-plugin-jest with ESLint instead.
gotcha Rules are only available via tslint.json; you cannot import them programmatically in code.
fix Always define rules in tslint.json configuration file.
gotcha expect-expect rule may flag tests with no explicit assertions inside `it` or `test` blocks even if they contain async calls that throw.
fix Use the `assertFunctionNames` option to whitelist custom assertion functions.
npm install tslint-jest
yarn add tslint-jest
pnpm add tslint-jest

Install tslint-jest, configure rules in tslint.json, and lint Jest test files.

// Step 1: Install
yarn add --dev tslint-jest

// Step 2: Configure tslint.json
{
  "extends": ["tslint-jest"],
  "rules": {
    "no-alias-methods": true,
    "expect-expect": [true, { "assertFunctionNames": ["expect", "assert"] }]
  }
}

// Step 3: Run tslint on a test file
npx tslint --project tsconfig.json 'src/**/*.test.ts'