bun:test/no-test-return-statement
Disallow return expect(..) in a test
The only thing worth returning from a test is a promise for bun test to wait for. A matcher such as toBe() returns nothing, so the return in return expect(total).toBe(3) has no effect. It only makes the test look like it waits for something.
The rule reports return expect(..).matcher(..) in a test or it callback, and in a function declaration that's passed to one of them. The matcher must be called directly on expect(..). With .resolves, .rejects or .not in between, the return isn't reported.
Configure#
Off by default. To turn it on:
[lint.rules]
"bun:test/no-test-return-statement" = "error" # or "warn"Examples#
import { expect, test } from "bun:test";
test("adds the prices", () => {
const total = sum([1, 2]);
returnTests should not return a value expect(total).toBe(3);
});import { expect, test } from "bun:test";
test("adds the prices", addsThePrices);
function addsThePrices() {
returnTests should not return a value expect(sum([1, 2])).toBe(3);
}import { expect, test } from "bun:test";
test("adds the prices", () => {
const total = sum([1, 2]);
expect(total).toBe(3);
});Other return statements aren't reported. That includes a returned promise, which bun test waits for:
import { expect, test } from "bun:test";
test("loads the prices", () => {
return expect(loadPrices()).resolves.toEqual([1, 2]);
});
test("loads the taxes", () => {
return loadTaxes().then(taxes => {
expect(taxes).toEqual([0.2]);
});
});bun:test/prefer-ending-with-an-expect reports a test that ends with a return. With both rules on, write await expect(..) instead.