Skip to content

Commit

Permalink
Fix no-standalone-expect false positive in helper methods
Browse files Browse the repository at this point in the history
This allows code such as the following to pass:

```
export class PageObjectModel {
  foo(x) {
    expect(x).toBeVisible();
  }
}
```
  • Loading branch information
joshkel committed Feb 19, 2024
1 parent 79af34f commit f1ca7cd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules/no-standalone-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const getBlockType = (
const expr = func.parent;

// arrow function or function expr
if (expr.type === 'VariableDeclarator') {
if (expr.type === 'VariableDeclarator' || expr.type === 'MethodDefinition') {
return 'function';
}

Expand Down
2 changes: 2 additions & 0 deletions test/spec/no-standalone-expect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ runRuleTester('no-standalone-expect', rule, {
'{}',
'test.only("an only", value => { expect(value).toBe(true); });',
'test.concurrent("an concurrent", value => { expect(value).toBe(true); });',
'class Helper { foo() { expect(1).toBe(1); } }',
'class Helper { foo = () => { expect(1).toBe(1); } }',
// Global aliases
{
code: dedent`
Expand Down

0 comments on commit f1ca7cd

Please sign in to comment.