Skip to content

Commit

Permalink
fix(prefer-expect-assertions): report on concise arrow functions with…
Browse files Browse the repository at this point in the history
… `expect` call (#1225)
  • Loading branch information
G-Rath committed Aug 28, 2022
1 parent 828651b commit 64ec9c1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/rules/__tests__/prefer-expect-assertions.test.ts
Expand Up @@ -115,6 +115,28 @@ ruleTester.run('prefer-expect-assertions', rule, {
},
],
},
{
code: "it('resolves', () => expect(staged()).toBe(true));",
errors: [
{
messageId: 'haveExpectAssertions',
column: 1,
line: 1,
suggestions: null,
},
],
},
{
code: "it('resolves', async () => expect(await staged()).toBe(true));",
errors: [
{
messageId: 'haveExpectAssertions',
column: 1,
line: 1,
suggestions: null,
},
],
},
{
code: 'it("it1", () => {})',
errors: [
Expand Down
11 changes: 6 additions & 5 deletions src/rules/prefer-expect-assertions.ts
Expand Up @@ -16,6 +16,12 @@ const isFirstStatement = (node: TSESTree.CallExpression): boolean => {
return parent.parent.body[0] === parent;
}

// if we've hit an arrow function, then it must have a single expression
// as its body, as otherwise we would have hit the block statement already
if (parent.parent?.type === AST_NODE_TYPES.ArrowFunctionExpression) {
return true;
}

parent = parent.parent;
}

Expand Down Expand Up @@ -52,11 +58,6 @@ type MessageIds =
| 'suggestAddingAssertions'
| 'suggestRemovingExtraArguments';

// const suggestions: Array<[MessageIds, string]> = [
// ['suggestAddingHasAssertions', 'expect.hasAssertions();'],
// ['suggestAddingAssertions', 'expect.assertions();'],
// ];

export default createRule<[RuleOptions], MessageIds>({
name: __filename,
meta: {
Expand Down

0 comments on commit 64ec9c1

Please sign in to comment.