eslint-plugin-jasmine

Build Status npm version License

ESLint rules for Jasmine

Usage

  1. Install eslint-plugin-jasmine as a dev-dependency:

    npm install --save-dev eslint-plugin-jasmine
    
  2. Enable the plugin by adding it to your .eslintrc:

    plugins:
      - jasmine
    

ESLint itself provides a Jasmine environment for Jasmine‘s global variables. It’s therefore recommended to also enable it in your .eslintrc:

plugins:
  - jasmine
env:
  jasmine: true

By default, no rules are enabled. See the next section for more.

Configuration

This plugin exports a recommended configuration that enforces good practices.

To enable this configuration, use the extends property in your .eslintrc config file:

plugins:
  - jasmine
env:
  jasmine: true
extends: 'plugin:jasmine/recommended'

See the ESLint config docs for more information about extending configuration files.

Rules

RuleRecommendedOptions
expect-matcher1,
expect-single-argument1,
missing-expect0, 'expect()', 'expectAsync()'expectation function names
named-spy0
new-line-before-expect1
new-line-between-declarations1
no-assign-spyon0
no-describe-variables0
no-disabled-tests1
no-expect-in-setup-teardown1, 'expect()', 'expectAsync()'expectation function names
no-focused-tests2
no-global-setup2
no-pending-tests1
no-promise-without-done-fail1
no-spec-dupes1, 'block'['block', 'branch']
no-suite-callback-args2
no-suite-dupes1, 'block'['block', 'branch']
no-unsafe-spy1
valid-expectdeprecated
prefer-jasmine-matcher1
prefer-promise-strategies1
prefer-toHaveBeenCalledWith1
prefer-toBeUndefined0['always', 'never']

For example, using the recommended configuration, the no-focused-tests rule is enabled and will cause ESLint to throw an error (with an exit code of 1) when triggered.

You may customise each rule by adding a value in your .eslintrc rules property:

plugins:
  - jasmine
env:
  jasmine: true
rules:
  jasmine/no-focused-tests: 0
  jasmine/no-suite-dupes:
    - 2
    - branch

See configuring rules for more information.

Author

© 2016 - 2017 Tom Vincent git@tlvince.com and contributors.

License

Released under the MIT license.