noDuplicateTestHooks
¥Summary
-
规则生效日期:
v1.6.0¥Rule available since:
v1.6.0 -
诊断类别:
lint/suspicious/noDuplicateTestHooks¥Diagnostic Category:
lint/suspicious/noDuplicateTestHooks -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
此规则属于以下域:
¥This rule belongs to the following domains:
-
来源:
¥Sources:
-
¥Inspired from
jest/no-duplicate-hooks -
灵感来自
vitest/no-duplicate-hooks¥Inspired from
vitest/no-duplicate-hooks
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noDuplicateTestHooks": "error" } } }}¥Description
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 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate beforeEach hook found.
3 │ // some setup
4 │ });
> 5 │ beforeEach(() => {
│ ^^^^^^^^^^^^^^^^^^
> 6 │ // some setup
> 7 │ });
│ ^^
8 │ test(‘foo_test’, () => {
9 │ // some test
ℹ Remove this duplicate hook or consolidate the logic into a single hook.
describe('foo', () => { beforeEach(() => { // some setup }); test('foo_test', () => { afterAll(() => { // some teardown }); afterAll(() => { // some teardown }); });});code-block.js:9:4 lint/suspicious/noDuplicateTestHooks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Duplicate afterAll hook found.
7 │ // some teardown
8 │ });
> 9 │ afterAll(() => {
│ ^^^^^^^^^^^^^^^^
> 10 │ // some teardown
> 11 │ });
│ ^^
12 │ });
13 │ });
ℹ Remove this duplicate hook or consolidate the logic into a single hook.
¥Valid
describe('foo', () => { beforeEach(() => { // some setup }); test('foo_test', () => { // some test });});¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号