jest/no-standalone-expect
eslint-plugin-jest
No autofixRecommended
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-standalone-expect": "error",
},
},
];// in describe
describe('a test', () => {
expect(1).toBe(1);
});
// below other tests
describe('a test', () => {
it('an it', () => {
expect(1).toBe(1);
});
expect(1).toBe(1);
});// in it block
describe('a test', () => {
it('an it', () => {
expect(1).toBe(1);
});
});
// in helper function
describe('a test', () => {
const helper = () => {
expect(1).toBe(1);
};
it('an it', () => {
helper();
});
});
describe('a test', () => {
beforeEach(() => {
expect.hasAssertions();
});
});Examples from the ESLint documentation.
jest/no-standalone-expect
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-standalone-expect": "error",
},
},
];jest/no-standalone-expect
jest plugin · correctness
{
"plugins": [
"jest"
],
"rules": {
"jest/no-standalone-expect": "error"
}
}suspicious/noMisplacedAssertion
suspicious · since 1.8.0
{
"linter": {
"rules": {
"suspicious": {
"noMisplacedAssertion": "error"
}
}
}
}Disallow using expect outside of it or test blocks
Disallow using a callback in asynchronous tests and hooks
Disallow calling expect conditionally