Skip to content
Permalink
Browse files
chore: merge no-empty-title into valid-title
BREAKING CHANEG: delete `no-empty-title` - use `valid-title` instead
  • Loading branch information
G-Rath committed Oct 27, 2019
1 parent 2ce233c commit bb2d09ea2084c12d6dc0b6fdb88c1fa8fa897273
@@ -117,7 +117,6 @@ installations requiring long-term consistency.
| [no-commented-out-tests][] | Disallow commented out tests | | |
| [no-disabled-tests][] | Disallow disabled tests | ![recommended][] | |
| [no-duplicate-hooks][] | Disallow duplicate hooks within a `describe` block | | |
| [no-empty-title][] | Disallow empty titles | | |
| [no-expect-resolves][] | Disallow using `expect().resolves` | | |
| [no-export][] | Disallow export from test files | | |
| [no-focused-tests][] | Disallow focused tests | ![recommended][] | |
@@ -173,7 +172,6 @@ https://github.com/dangreenisrael/eslint-plugin-jest-formatting
[no-commented-out-tests]: docs/rules/no-commented-out-tests.md
[no-disabled-tests]: docs/rules/no-disabled-tests.md
[no-duplicate-hooks]: docs/rules/no-duplicate-hooks.md
[no-empty-title]: docs/rules/no-empty-title.md
[no-expect-resolves]: docs/rules/no-expect-resolves.md
[no-export]: docs/rules/no-export.md
[no-focused-tests]: docs/rules/no-focused-tests.md

This file was deleted.

@@ -2,11 +2,44 @@

Checks that the title of Jest blocks are valid by ensuring that titles are:

- not empty,
- not prefixed with their block name,
- have no leading or trailing spaces

## Rule Details

**emptyTitle**

An empty title is not informative, and serves little purpose.

Examples of **incorrect** code for this rule:

```js
describe('', () => {});
describe('foo', () => {
it('', () => {});
});
it('', () => {});
test('', () => {});
xdescribe('', () => {});
xit('', () => {});
xtest('', () => {});
```

Examples of **correct** code for this rule:

```js
describe('foo', () => {});
describe('foo', () => {
it('bar', () => {});
});
test('foo', () => {});
it('foo', () => {});
xdescribe('foo', () => {});
xit('foo', () => {});
xtest('foo', () => {});
```

**duplicatePrefix**

A describe/ test block should not start with duplicatePrefix
@@ -3,7 +3,7 @@ import { resolve } from 'path';
import plugin from '../';

const ruleNames = Object.keys(plugin.rules);
const numberOfRules = 41;
const numberOfRules = 40;

describe('rules', () => {
it('should have a corresponding doc for each rule', () => {

This file was deleted.

@@ -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 () {})',

This file was deleted.

@@ -3,6 +3,8 @@ import {
TSESTree,
} from '@typescript-eslint/experimental-utils';
import {
DescribeAlias,
TestCaseName,
createRule,
getNodeName,
getStringValue,
@@ -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',
},
@@ -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;
}

5 comments on commit bb2d09e

@dylanwulf
Copy link

@dylanwulf dylanwulf commented on bb2d09e Jan 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't listed as a breaking change on the releases page

@G-Rath
Copy link
Collaborator Author

@G-Rath G-Rath commented on bb2d09e Jan 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dylanwulf Correct - that is because of a typo I made in the commit.

@SimenB
Copy link
Member

@SimenB SimenB commented on bb2d09e Jan 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update the release and changelog though. @G-Rath wanna do it?

EDIT: It probably isn't in the changelog sa I haven't gotten around to updating it with old releases yet

@G-Rath
Copy link
Collaborator Author

@G-Rath G-Rath commented on bb2d09e Jan 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimenB Good thinking - I'll do it now.

I'm a little confused to why it didn't appear in the CHANGELOG for 23.0.0 at all, as that's got a chore title 🤔

@SimenB
Copy link
Member

@SimenB SimenB commented on bb2d09e Jan 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it seems like chore updates are not included in releases, so we'll have to use another notation.

Please sign in to comment.