eslint-plugin-jest
Version:
Eslint rules for Jest
50 lines (47 loc) • 1.05 kB
JavaScript
;
const {
getDocsUrl,
hasExpressions,
isDescribe,
isTestCase,
isTemplateLiteral,
isString,
getStringValue,
} = require('./util');
module.exports = {
meta: {
docs: {
url: getDocsUrl(__filename),
},
messages: {
describe: 'describe should not have an empty title',
test: 'test should not have an empty title',
},
},
create(context) {
return {
CallExpression(node) {
const is = {
describe: isDescribe(node),
testCase: isTestCase(node),
};
if (!is.describe && !is.testCase) {
return;
}
const [firstArgument] = node.arguments;
if (!isString(firstArgument)) {
return;
}
if (isTemplateLiteral(firstArgument) && hasExpressions(firstArgument)) {
return;
}
if (getStringValue(firstArgument) === '') {
context.report({
messageId: is.describe ? 'describe' : 'test',
node,
});
}
},
};
},
};