Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Rule - no-duplicate-hooks #298

Merged
merged 5 commits into from Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
SimenB marked this conversation as resolved.
Show resolved Hide resolved
[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