Skip to content

noDuplicateTestHooks

诊断类别:lint/suspicious/noDuplicateTestHooks

¥Diagnostic Category: lint/suspicious/noDuplicateTestHooks

自从:v1.6.0

¥Since: v1.6.0

来源:

¥Sources:

describe 块不应包含重复的钩子。

¥A describe block should not contain duplicate hooks.

¥Examples

¥Invalid

describe('foo', () => {
beforeEach(() => {
// some setup
});
beforeEach(() => {
// some setup
});
test('foo_test', () => {
// some test
});
});
code-block.js:5:3 lint/suspicious/noDuplicateTestHooks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Disallow duplicate setup and teardown hooks.

3 │ // some setup
4 │ });
> 5 │ beforeEach(() => {
^^^^^^^^^^^^^^^^^^
> 6 │ // some setup
> 7 │ });
^^
8 │ test(‘foo_test’, () => {
9 │ // some test

Disallow beforeEach duplicacy inside the describe function.

describe('foo', () => {
beforeEach(() => {
// some setup
});
test('foo_test', () => {
afterAll(() => {
// some teardown
});
afterAll(() => {
// some teardown
});
});
});
code-block.js:9:4 lint/suspicious/noDuplicateTestHooks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Disallow duplicate setup and teardown hooks.

7 │ // some teardown
8 │ });
> 9 │ afterAll(() => {
^^^^^^^^^^^^^^^^
> 10 │ // some teardown
> 11 │ });
^^
12 │ });
13 │ });

Disallow afterAll duplicacy inside the describe function.

¥Valid

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

¥Related links