noDoneCallback
诊断类别:lint/style/noDoneCallback
¥Diagnostic Category: lint/style/noDoneCallback
自从:v1.6.1
来源:
¥Since: v1.6.1
Sources:
-
与以下相同:
jest/no-done-callback
¥Same as:
jest/no-done-callback
禁止在异步测试和钩子中使用回调。
¥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