jest/prefer-ending-with-an-expect
eslint-plugin-jest
No autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-ending-with-an-expect": "error",
},
},
];Prefer having the last statement in a test be an assertion
it('lets me change the selected option', () => {
const container = render(MySelect, {
props: { options: [1, 2, 3], selected: 1 },
});
expect(container).toBeDefined();
expect(container.toHTML()).toContain('<option value="1" selected>');
container.setProp('selected', 2);
});it('lets me change the selected option', () => {
const container = render(MySelect, {
props: { options: [1, 2, 3], selected: 1 },
});
expect(container).toBeDefined();
expect(container.toHTML()).toContain('<option value="1" selected>');
container.setProp('selected', 2);
expect(container.toHTML()).not.toContain('<option value="1" selected>');
expect(container.toHTML()).toContain('<option value="2" selected>');
});Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
jest/prefer-ending-with-an-expect
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-ending-with-an-expect": "error",
},
},
];jest/prefer-ending-with-an-expect
jest plugin · style
{
"plugins": [
"jest"
],
"rules": {
"jest/prefer-ending-with-an-expect": "error"
}
}Biome does not have this rule.
Suggest using expect.assertions() OR expect.hasAssertions()
Suggest using the built-in comparison matchers
Prefer await expect(...).resolves over expect(await ...) syntax
Enforce padding around test and it blocks