Enforces BDD style comments (given/when/then) in your JavaScript tests! Rule is inspired by Spock framework.
with npm:
npm i -D eslint-plugin-test-comments
or yarn:
yarn add -D eslint-plugin-test-comments
"plugins": [
"test-comments"
],
"rules": {
"test-comments/test-comments": "error"
}
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
}]
}
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', () => {});