Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(rules): no-duplicate-hooks (#298)
Fixes #231
  • Loading branch information
Mark1626 authored and SimenB committed Jul 15, 2019
1 parent a3a6dca commit dd4bbaf
Show file tree
Hide file tree
Showing 8 changed files with 492 additions and 38 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -112,6 +112,7 @@ installations requiring long-term consistency.
| [no-alias-methods][] | Disallow alias methods | ![recommended][] | ![fixable-green][] |
| [no-disabled-tests][] | Disallow disabled tests | ![recommended][] | |
| [no-commented-out-tests][] | Disallow commented out tests | | |
| [no-duplicate-hooks][] | Disallow duplicate hooks withing a `describe` block | | |
| [no-empty-title][] | Disallow empty titles | | |
| [no-focused-tests][] | Disallow focused tests | ![recommended][] | |
| [no-hooks][] | Disallow setup and teardown hooks | | |
Expand Down Expand Up @@ -158,6 +159,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 dd4bbaf

Please sign in to comment.