sonarjs/assertions-in-tests
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/assertions-in-tests": "error",
},
},
];const expect = require('chai').expect;
describe("No assertion", function() {
it("doesn't test anything", function() { // Noncompliant
const str = "";
});
});const expect = require('chai').expect;
describe("Has assertions", function() {
it("tests a string", function() {
const str = "";
expect(str).to.be.a('string');
});
});Examples from the ESLint documentation.
sonarjs/assertions-in-tests
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/assertions-in-tests": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Assertions should be placed inside test cases or hooks
Async test assertions should be awaited or returned
Callbacks of array methods should have return statements
Nested properties of Lodash and Underscore.js clone results should not be mutated
AWS API Gateway should require authentication