noDuplicateTestHooks
Este conteúdo não está disponível em sua língua ainda.
Summary
Section titled “Summary”- Rule available since:
v1.6.0 - Diagnostic Category:
lint/suspicious/noDuplicateTestHooks - This rule doesn’t have a fix.
- The default severity of this rule is error.
- This rule belongs to the following domains:
- Sources:
- Inspired from
jest/no-duplicate-hooks - Inspired from
vitest/no-duplicate-hooks
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "noDuplicateTestHooks": "error" } } }}Description
Section titled “Description”A describe block should not contain duplicate hooks.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”describe('foo', () => { beforeEach(() => { // some setup }); beforeEach(() => { // some setup }); test('foo_test', () => { // some test });});code-block.js:5:3 lint/suspicious/noDuplicateTestHooks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The test hook beforeEach is used multiple times in the same test block.
3 │ // some setup
4 │ });
> 5 │ beforeEach(() => {
│ ^^^^^^^^^^^^^^^^^^
> 6 │ // some setup
> 7 │ });
│ ^^
8 │ test(‘foo_test’, () => {
9 │ // some test
ℹ The presence of the same hook more than once in the same test block can create unexpected errors inside tests. Remove one of them.
describe('foo', () => { beforeEach(() => { // some setup }); test('foo_test', () => { afterAll(() => { // some teardown }); afterAll(() => { // some teardown }); });});code-block.js:9:4 lint/suspicious/noDuplicateTestHooks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The test hook afterAll is used multiple times in the same test block.
7 │ // some teardown
8 │ });
> 9 │ afterAll(() => {
│ ^^^^^^^^^^^^^^^^
> 10 │ // some teardown
> 11 │ });
│ ^^
12 │ });
13 │ });
ℹ The presence of the same hook more than once in the same test block can create unexpected errors inside tests. Remove one of them.
describe('foo', () => { beforeEach(() => { // some setup }); test('foo_test', () => { // some test });});Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.