Skip to content

Commit

Permalink
Don’t report identifier as empty title
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed Dec 13, 2021
1 parent 744d7fa commit e550a7e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/rules/no-empty-description.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { getStringIfConstant } = require('eslint-utils');
const { getStringIfConstant, getStaticValue } = require('eslint-utils');

const DEFAULT_TEST_NAMES = [ 'describe', 'context', 'suite', 'it', 'test', 'specify' ];
const ERROR_MESSAGE = 'Unexpected empty test description.';
Expand Down Expand Up @@ -55,14 +55,22 @@ module.exports = {
return [ 'TaggedTemplateExpression', 'TemplateLiteral' ].includes(node && node.type);
}

function isIdentifier(node) {
return node && node.type === 'Identifier';
}

function checkDescription(mochaCallExpression) {
const description = mochaCallExpression.arguments[0];
const text = getStringIfConstant(description);
const text = getStringIfConstant(description, context.getScope());

if (isTemplateString(description) && text === null) {
return true;
}

if (isIdentifier(description) && text === null) {
return true;
}

return text && text.trim().length;
}

Expand Down
12 changes: 12 additions & 0 deletions test/rules/no-empty-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ ruleTester.run('no-empty-description', rules['no-empty-description'], {
'test.only("some text")',
'test("some text", function() { })',

'var dynamicTitle = "foo"; it(dynamicTitle, function() {});',
'it(dynamicTitle, function() {});',

'notTest()',

{
Expand All @@ -46,6 +49,10 @@ ruleTester.run('no-empty-description', rules['no-empty-description'], {
{
options: [ { testNames: [ 'someFunction' ] } ],
code: 'someFunction("this is a test", function () { });'
},
{
parserOptions: { ecmaVersion: 2019 },
code: 'const dynamicTitle = "foo"; it(dynamicTitle, function() {});'
}
],

Expand Down Expand Up @@ -76,6 +83,11 @@ ruleTester.run('no-empty-description', rules['no-empty-description'], {
parserOptions: { ecmaVersion: 2019 },
code: 'it(` `, function () { });',
errors: [ { message: defaultErrorMessage, ...firstLine } ]
},
{
parserOptions: { ecmaVersion: 2019 },
code: 'const foo = ""; it(foo);',
errors: [ { message: defaultErrorMessage, line: 1, column: 17 } ]
}
]

Expand Down

0 comments on commit e550a7e

Please sign in to comment.