Skip to content

Commit 9c2670a

Browse files
aryaemami59veritem
andauthored
fix: valid-title false positives when test.extend is used (#584)
* Fix `valid-title` false positive when `test.extend` is used * chore: update --------- Co-authored-by: Verite Mugabo <mugaboverite@gmail.com>
1 parent d832860 commit 9c2670a

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/rules/valid-title.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,16 @@ export default createEslintRule<Options, MESSAGE_IDS>({
197197

198198
if (vitestFnCall?.type !== 'describe' && vitestFnCall?.type !== 'test' && vitestFnCall?.type !== 'it') return
199199

200+
200201
// check if extend keyword have been used
201-
if (vitestFnCall.members.some(m => m.type == AST_NODE_TYPES.Identifier && m.name == 'extend')) return
202+
if (
203+
vitestFnCall.members &&
204+
vitestFnCall.members[0] &&
205+
vitestFnCall.members[0].type === AST_NODE_TYPES.Identifier &&
206+
vitestFnCall.members[0].name === 'extend'
207+
) {
208+
return
209+
}
202210

203211
const [argument] = node.arguments
204212

tests/valid-title.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,3 +605,31 @@ ruleTester.run(RULE_NAME, rule, {
605605
}
606606
]
607607
})
608+
609+
ruleTester.run(RULE_NAME, rule, {
610+
valid: [
611+
{
612+
code: 'const localTest = test.extend({})',
613+
name: 'does not error when using test.extend'
614+
},
615+
{
616+
code: `import { it } from 'vitest'
617+
618+
const test = it.extend({
619+
fixture: [
620+
async ({}, use) => {
621+
setup()
622+
await use()
623+
teardown()
624+
},
625+
{ auto: true }
626+
],
627+
})
628+
629+
test('', () => {})`,
630+
name: 'does not error when using it.extend'
631+
}
632+
],
633+
634+
invalid: []
635+
})

0 commit comments

Comments
 (0)