Back to Biomejs

noDoneCallback

src/content/docs/linter/rules/no-done-callback.mdx

latest4.1 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.6.1` - Diagnostic Category: [`lint/style/noDoneCallback`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`jest/no-done-callback`](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-done-callback.md) - Same as [`vitest/no-done-callback`](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-done-callback.md)

How to configure

json
{
	"linter": {
		"rules": {
			"style": {
				"noDoneCallback": "error"
			}
		}
	}
}

Description

Disallow using a callback in asynchronous tests and hooks.

This rule checks the function parameter of hooks and tests for use of the done argument, suggesting you return a promise instead.

Examples

Invalid

js
beforeEach((done) => {
    // ...
});
<pre class="language-text"><code class="language-text">code-block.js:1:13 <a href="https://biomejs.dev/linter/rules/no-done-callback">lint/style/noDoneCallback</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Disallow using a callback in asynchronous tests and hooks.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>beforeEach((done) =&gt; &#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> // ... <strong>3 │ </strong>&#125;); <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Return a Promise instead of relying on callback parameter.</span> </code></pre>
js
test('tets-name', (done) => {
    // ...
});
<pre class="language-text"><code class="language-text">code-block.js:1:20 <a href="https://biomejs.dev/linter/rules/no-done-callback">lint/style/noDoneCallback</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Disallow using a callback in asynchronous tests and hooks.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>test('tets-name', (done) =&gt; &#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> // ... <strong>3 │ </strong>&#125;); <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Return a Promise instead of relying on callback parameter.</span> </code></pre>

Valid

js
beforeEach(async () => {
    // ...
});
js
test('test-name', () => {
    expect(myFunction()).toBeTruthy();
});
</TabItem> </Tabs>