Skip to content

Commit

Permalink
fix(valid-describe): report on concise-body arrow functions (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfranco committed Jul 21, 2021
1 parent 38f8436 commit 71c5299
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 6 additions & 0 deletions docs/rules/valid-describe.md
Expand Up @@ -43,6 +43,12 @@ describe('myFunction', () => {
});
});
});

// Returning a value from a describe block is not allowed
describe('myFunction', () =>
it('returns a truthy value', () => {
expect(myFunction()).toBeTruthy();
}));
```

The following patterns are not considered warnings:
Expand Down
15 changes: 10 additions & 5 deletions src/rules/__tests__/valid-describe.test.ts
Expand Up @@ -36,11 +36,6 @@ ruleTester.run('valid-describe', rule, {
})
})
`,
dedent`
describe('foo', () =>
test('bar', () => {})
)
`,
dedent`
if (hasOwnProperty(obj, key)) {
}
Expand Down Expand Up @@ -196,6 +191,16 @@ ruleTester.run('valid-describe', rule, {
{ messageId: 'unexpectedReturnInDescribe', line: 5, column: 5 },
],
},
{
code: dedent`
describe('foo', () =>
test('bar', () => {})
)
`,
errors: [
{ messageId: 'unexpectedReturnInDescribe', line: 1, column: 17 },
],
},
{
code: 'describe("foo", done => {})',
errors: [
Expand Down
7 changes: 7 additions & 0 deletions src/rules/valid-describe.ts
Expand Up @@ -84,6 +84,13 @@ export default createRule({
});
}

if (callback.body.type === AST_NODE_TYPES.CallExpression) {
context.report({
messageId: 'unexpectedReturnInDescribe',
node: callback,
});
}

if (callback.body.type === AST_NODE_TYPES.BlockStatement) {
callback.body.body.forEach(node => {
if (node.type === AST_NODE_TYPES.ReturnStatement) {
Expand Down

0 comments on commit 71c5299

Please sign in to comment.