Skip to content

Commit

Permalink
fix: detect expectations in chains with underscores (#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghusse authored Dec 19, 2024
1 parent 2abdad0 commit d31fdb7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/rules/expect-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function matchesAssertFunctionName(
.split('.')
.map((x) => {
if (x === '**')
return '[a-z\\d\\.]*'
return '[_a-z\\d\\.]*'
return x.replace(/\*/gu, '[a-z\\d]*')
})
Expand Down
17 changes: 13 additions & 4 deletions tests/expect-expect.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
import rule, { RULE_NAME } from '../src/rules/expect-expect'
import { ruleTester } from './ruleTester'
import { AST_NODE_TYPES } from '@typescript-eslint/utils';

import rule, { RULE_NAME } from '../src/rules/expect-expect';
import { ruleTester } from './ruleTester';

ruleTester.run(RULE_NAME, rule, {
valid: [
Expand Down Expand Up @@ -42,7 +43,15 @@ it('example', async () => {
const result = Promise.reject<string>('error');
await expect(result.then((it) => it.toUpperCase())).rejects.toThrow();
});`
});`,
{
code: `it("should pass", () => { anyChain.of.calls.expect(true) })`,
options: [{ assertFunctionNames: ['**.expect'] }]
},
{
code: `it("should pass", () => { any_chain.of.calls.expect(true) })`,
options: [{ assertFunctionNames: ['**.expect'] }]
}
],
invalid: [
{
Expand Down

0 comments on commit d31fdb7

Please sign in to comment.