allegro / eslint-plugin-test-comments

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eslint-plugin-test-comments

Enforces BDD style comments (given/when/then) in your JavaScript tests! Rule is inspired by Spock framework.

Installation

with npm:

npm i -D eslint-plugin-test-comments

or yarn:

yarn add -D eslint-plugin-test-comments

Configuration

"plugins": [
  "test-comments"
],
"rules": {
  "test-comments/test-comments": "error"
}

Options

This rule accepts one boolean option:

allowNoComments: does not report any errors when there are no BDD comments in a test, defaults with false.

For example:

{
  "test-comments/test-comments": ["error", {
    allowNoComments: true
  }]
}

Rule Details

Examples of incorrect code.

it('test', () => {
  // given
  // and
  // given 
});
it('test', () => {
  // and
  // given 
  // when 
});
it('test', () => {});

Examples of correct code

it('test', () => {
  // given
  // and
  // when
  // then
});
it('test', () => {
  // given something
  // and something else
  // when something occurs
  // then something should work
  // some other comment
});

Examples of correct code with allowNoComments option.

it('test', () => {});

About

License:MIT License


Languages

Language:TypeScript 96.3%Language:JavaScript 3.7%