eslint-plugin-jasmine
raw JSON → 4.2.2 verified Sat Apr 25 auth: no javascript
ESLint plugin providing linting rules for Jasmine test suites. Current stable version is 4.2.2 (September 2024). Release cadence is irregular with minor patches and occasional feature releases. Key differentiators: it is the most widely used ESLint plugin for Jasmine, with a comprehensive set of rules covering common anti-patterns like focused tests, disabled tests, missing expectations, and improper use of spies. Includes a recommended configuration. Note: v4.2.0+ supports ESLint v9 flat config with some caveats (beta). Requires Node >=8 and npm >=6. Alternative: eslint-plugin-jasmine-no-describe-variables (lighter scope).
Common errors
error Definition for rule 'jasmine/prefer-toBeUndefined' was not found ↓
cause Rule was added in v4.1.0 but some configurations might have a typo or old version.
fix
Update to eslint-plugin-jasmine@4.1.2+ and ensure rule name is correct: 'prefer-toBeUndefined' (with two 'e's).
error ESLint: Failed to load plugin 'jasmine' declared in '.eslintrc': Cannot find module 'eslint-plugin-jasmine' ↓
cause Plugin not installed or not in node_modules.
fix
Run npm install --save-dev eslint-plugin-jasmine. Ensure you're in the correct project directory.
error Configuration for rule 'jasmine/no-focused-tests' is invalid: Severity should be one of the following: 0 = off, 1 = warn, 2 = error ↓
cause Rule severity set to incorrect value (e.g., string or boolean).
fix
Set rule severity to 0, 1, or 2. E.g., 'jasmine/no-focused-tests': 'error' works as well.
error Cannot read property 'globals' of undefined when using plugin.environments.jasmine in flat config ↓
cause Flat config requires importing from the plugin directly; environments might not be exported in older versions.
fix
Use plugin.languageOptions?.globals or manually set globals. Upgrade to latest version.
Warnings
breaking ESLint v9 flat config support is experimental (v4.2.0-beta). Flat config consumers must import the plugin and manually set globals or use plugin.configs.recommended with caution. ↓
fix Follow flat config example in README. Use stable v4.1.x if not ready for betas.
deprecated Rule 'jasmine/valid-expect' is deprecated and will be removed in future versions. ↓
fix Remove rule from config; use built-in ESLint valid-expect or other rules.
gotcha The plugin does not automatically enable the Jasmine environment. You must set env: { jasmine: true } in .eslintrc or configure globals manually in flat config. ↓
fix Add env: { jasmine: true } in your ESLint config.
gotcha Rule 'jasmine/expect-single-argument' may report false positives when using no matcher (e.g., expect(something)). Fixed in v4.2.2 but still tricky when using nothing. ↓
fix Upgrade to v4.2.2 or configure rule to allow no arguments.
gotcha In v4.2.0, rules were refactored to export an object with a 'create' method. Custom rule implementations relying on old format may break. ↓
fix Update custom rules to follow ESLint rule format: module.exports = { meta: {...}, create(context) { return {...} } }.
Install
npm install eslint-plugin-jasmine yarn add eslint-plugin-jasmine pnpm add eslint-plugin-jasmine Imports
- plugin wrong
using require('eslint-plugin-jasmine') without default import in ESM projectscorrectimport plugin from 'eslint-plugin-jasmine'; or use as 'jasmine' in .eslintrc plugins array - recommended config wrong
using 'jasmine/recommended' without 'plugin:' prefix in older ESLint versionscorrectextends: 'plugin:jasmine/recommended' in .eslintrc or import { recommended } from 'eslint-plugin-jasmine' in flat config - env wrong
assuming plugin automatically sets the Jasmine globals without envcorrectenv: { jasmine: true } in .eslintrc or environments: { jasmine: true } in flat config
Quickstart
// .eslintrc.js
module.exports = {
plugins: ['jasmine'],
env: { jasmine: true },
extends: ['plugin:jasmine/recommended'],
rules: {
'jasmine/no-focused-tests': 'error',
'jasmine/no-disabled-tests': 'warn',
},
};
// For ESLint flat config (eslint.config.js)
import plugin from 'eslint-plugin-jasmine';
export default [
{
plugins: { jasmine: plugin },
languageOptions: { globals: { ...plugin.environments.jasmine.globals } },
rules: {
...plugin.configs.recommended.rules,
'jasmine/no-focused-tests': 'error',
},
},
];