Skip to content

Commit

Permalink
chore: merge no-empty-title into valid-title
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Oct 27, 2019
1 parent 88a2921 commit 60443d2
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 1 deletion.
108 changes: 107 additions & 1 deletion src/rules/__tests__/valid-title.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,117 @@ const ruleTester = new TSESLint.RuleTester({
},
});

ruleTester.run('no-empty-title', rule, {
valid: [
'describe()',
'someFn("", function () {})',
'describe(1, function () {})',
'describe("foo", function () {})',
'describe("foo", function () { it("bar", function () {}) })',
'test("foo", function () {})',
'test(`foo`, function () {})',
'test(`${foo}`, function () {})',
"it('foo', function () {})",
"xdescribe('foo', function () {})",
"xit('foo', function () {})",
"xtest('foo', function () {})",
],
invalid: [
{
code: 'describe("", function () {})',
errors: [
{
messageId: 'emptyTitle',
column: 1,
line: 1,
data: { jestFunctionName: 'describe' },
},
],
},
{
code: ["describe('foo', () => {", "it('', () => {})", '})'].join('\n'),
errors: [
{
messageId: 'emptyTitle',
column: 1,
line: 2,
data: { jestFunctionName: 'test' },
},
],
},
{
code: 'it("", function () {})',
errors: [
{
messageId: 'emptyTitle',
column: 1,
line: 1,
data: { jestFunctionName: 'test' },
},
],
},
{
code: 'test("", function () {})',
errors: [
{
messageId: 'emptyTitle',
column: 1,
line: 1,
data: { jestFunctionName: 'test' },
},
],
},
{
code: 'test(``, function () {})',
errors: [
{
messageId: 'emptyTitle',
column: 1,
line: 1,
data: { jestFunctionName: 'test' },
},
],
},
{
code: "xdescribe('', () => {})",
errors: [
{
messageId: 'emptyTitle',
column: 1,
line: 1,
data: { jestFunctionName: 'describe' },
},
],
},
{
code: "xit('', () => {})",
errors: [
{
messageId: 'emptyTitle',
column: 1,
line: 1,
data: { jestFunctionName: 'test' },
},
],
},
{
code: "xtest('', () => {})",
errors: [
{
messageId: 'emptyTitle',
column: 1,
line: 1,
data: { jestFunctionName: 'test' },
},
],
},
],
});

ruleTester.run('no-accidental-space', rule, {
valid: [
'it()',
'describe()',
'it("")',
'it.each()()',
'describe("foo", function () {})',
'describe(6, function () {})',
Expand Down
15 changes: 15 additions & 0 deletions src/rules/valid-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
TSESTree,
} from '@typescript-eslint/experimental-utils';
import {
DescribeAlias,
TestCaseName,
createRule,
getNodeName,
getStringValue,
Expand All @@ -23,6 +25,7 @@ export default createRule({
recommended: false,
},
messages: {
emptyTitle: '{{ jestFunctionName }} should not have an empty title',
duplicatePrefix: 'should not have duplicate prefix',
accidentalSpace: 'should not have leading or trailing spaces',
},
Expand All @@ -47,6 +50,18 @@ export default createRule({
const title = getStringValue(argument);

if (!title) {
if (typeof title === 'string') {
context.report({
messageId: 'emptyTitle',
data: {
jestFunctionName: isDescribe(node)
? DescribeAlias.describe
: TestCaseName.test,
},
node,
});
}

return;
}

Expand Down

0 comments on commit 60443d2

Please sign in to comment.