noDoneCallback
¥Summary
-
规则生效日期:
v1.6.1¥Rule available since:
v1.6.1 -
诊断类别:
lint/style/noDoneCallback¥Diagnostic Category:
lint/style/noDoneCallback -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
¥Same as
jest/no-done-callback -
¥Same as
vitest/no-done-callback
-
¥How to configure
{ "linter": { "rules": { "style": { "noDoneCallback": "error" } } }}¥Description
禁止在异步测试和钩子中使用回调。
¥Disallow using a callback in asynchronous tests and hooks.
此规则检查钩子的函数参数并测试是否使用 done 参数,建议你改为返回承诺。
¥This rule checks the function parameter of hooks and tests for use of the done argument, suggesting you return a promise instead.
¥Examples
¥Invalid
beforeEach((done) => { // ...});code-block.js:1:13 lint/style/noDoneCallback ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Disallow using a callback in asynchronous tests and hooks.
> 1 │ beforeEach((done) => {
│ ^^^^
2 │ // …
3 │ });
ℹ Return a Promise instead of relying on callback parameter.
test('tets-name', (done) => { // ...});code-block.js:1:20 lint/style/noDoneCallback ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Disallow using a callback in asynchronous tests and hooks.
> 1 │ test(‘tets-name’, (done) => {
│ ^^^^
2 │ // …
3 │ });
ℹ Return a Promise instead of relying on callback parameter.
¥Valid
beforeEach(async () => { // ...});test('test-name', () => { expect(myFunction()).toBeTruthy();});¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号