jest/no-test-return-statement
eslint-plugin-jest
No autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-test-return-statement": "error",
},
},
];test("adds two numbers", () => {
return expect(add(1, 2)).toBe(3);
});it("loads the user", function () {
return loadUser().then((user) => expect(user.name).toBe("Ada"));
});it("loads the user", loadsTheUser);
function loadsTheUser() {
return loadUser().then((user) => expect(user.name).toBe("Ada"));
}test("adds two numbers", () => {
expect(add(1, 2)).toBe(3);
});
test("subtracts two numbers", () => expect(subtract(3, 2)).toBe(1));
it("loads the user", async () => {
const user = await loadUser();
expect(user.name).toBe("Ada");
});
it("saves the user", async () => {
if (isReadOnly) {
return;
}
await saveUser();
});Examples from the Biome documentation.
jest/no-test-return-statement
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-test-return-statement": "error",
},
},
];jest/no-test-return-statement
jest plugin · style
{
"plugins": [
"jest"
],
"rules": {
"jest/no-test-return-statement": "error"
}
}nursery/noReturnInTest
nursery · since 2.6.9
{
"linter": {
"rules": {
"nursery": {
"noReturnInTest": "error"
}
}
}
}Disallow return statements in tests
Disallow duplicate setup and teardown hooks
Enforce assertion to be made in a test body
Disallow calling expect conditionally