Skip to content

Commit

Permalink
feat: add rule no-duplicate-hook jest-community#231
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark1626 committed Jul 11, 2019
1 parent 8f57efc commit cdb17a7
Show file tree
Hide file tree
Showing 5 changed files with 436 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -158,6 +158,7 @@ https://github.com/dangreenisrael/eslint-plugin-jest-formatting
[lowercase-name]: docs/rules/lowercase-name.md
[no-alias-methods]: docs/rules/no-alias-methods.md
[no-disabled-tests]: docs/rules/no-disabled-tests.md
[no-duplicate-hooks]: docs/rules/no-duplicate-hooks.md
[no-commented-out-tests]: docs/rules/no-commented-out-tests.md
[no-empty-title]: docs/rules/no-empty-title.md
[no-focused-tests]: docs/rules/no-focused-tests.md
Expand Down
75 changes: 75 additions & 0 deletions docs/rules/no-duplicate-hooks.md
@@ -0,0 +1,75 @@
# Disallow duplicate setup and teardown hooks (no-duplicate-hooks)

A describe block should not contain duplicate hooks.

## Rule Details

Examples of **incorrect** code for this rule

```js
/* eslint jest/no-duplicate-hooks: "error" */

describe('foo', () => {
beforeEach(() => {
// some setup
});
beforeEach(() => {
// some setup
});
test('foo_test', () => {
// some test
});
});

// Nested describe scenario
describe('foo', () => {
beforeEach(() => {
// some setup
});
test('foo_test', () => {
// some test
});
describe('bar', () => {
test('bar_test', () => {
afterAll(() => {
// some teardown
});
afterAll(() => {
// some teardown
});
});
});
});
```

Examples of **correct** code for this rule

```js
/* eslint jest/no-duplicate-hooks: "error" */

describe('foo', () => {
beforeEach(() => {
// some setup
});
test('foo_test', () => {
// some test
});
});

// Nested describe scenario
describe('foo', () => {
beforeEach(() => {
// some setup
});
test('foo_test', () => {
// some test
});
describe('bar', () => {
test('bar_test', () => {
beforeEach(() => {
// some setup
});
});
});
});
```
2 changes: 1 addition & 1 deletion src/__tests__/rules.test.js
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const { rules } = require('../');

const ruleNames = Object.keys(rules);
const numberOfRules = 32;
const numberOfRules = 33;

describe('rules', () => {
it('should have a corresponding doc for each rule', () => {
Expand Down

0 comments on commit cdb17a7

Please sign in to comment.