Skip to content

Commit b7c1be2

Browse files
authoredOct 28, 2019
fix(valid-title): ignore string addition (#461)
1 parent 10e5087 commit b7c1be2

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
 

‎src/rules/__tests__/valid-title.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const ruleTester = new TSESLint.RuleTester({
1212
ruleTester.run('title-must-be-string', rule, {
1313
valid: [
1414
'it("is a string", () => {});',
15+
'it("is" + " a " + " string", () => {});',
16+
'it(1 + " + " + 1, () => {});',
1517
'test("is a string", () => {});',
1618
'xtest("is a string", () => {});',
1719
'xtest(`${myFunc} is a string`, () => {});',
@@ -53,6 +55,16 @@ ruleTester.run('title-must-be-string', rule, {
5355
},
5456
],
5557
},
58+
{
59+
code: 'it(1 + 2 + 3, () => {});',
60+
errors: [
61+
{
62+
messageId: 'titleMustBeString',
63+
column: 4,
64+
line: 1,
65+
},
66+
],
67+
},
5668
{
5769
code: 'test.skip(123, () => {});',
5870
options: [{ ignoreTypeOfDescribeName: true }],

‎src/rules/valid-title.ts

+21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ import {
1717
const trimFXprefix = (word: string) =>
1818
['f', 'x'].includes(word.charAt(0)) ? word.substr(1) : word;
1919

20+
const doesBinaryExpressionContainStringNode = (
21+
binaryExp: TSESTree.BinaryExpression,
22+
): boolean => {
23+
if (isStringNode(binaryExp.right)) {
24+
return true;
25+
}
26+
27+
if (binaryExp.left.type === AST_NODE_TYPES.BinaryExpression) {
28+
return doesBinaryExpressionContainStringNode(binaryExp.left);
29+
}
30+
31+
return isStringNode(binaryExp.left);
32+
};
33+
2034
export default createRule({
2135
name: __filename,
2236
meta: {
@@ -57,6 +71,13 @@ export default createRule({
5771
const [argument] = getJestFunctionArguments(node);
5872

5973
if (!isStringNode(argument)) {
74+
if (
75+
argument.type === AST_NODE_TYPES.BinaryExpression &&
76+
doesBinaryExpressionContainStringNode(argument)
77+
) {
78+
return;
79+
}
80+
6081
if (
6182
argument.type !== AST_NODE_TYPES.TemplateLiteral &&
6283
!(ignoreTypeOfDescribeName && isDescribe(node))

0 commit comments

Comments
 (0)
Please sign in to comment.