Skip to content

Commit 6f332c5

Browse files
committedDec 16, 2023
fix(no-identical-title): improved internal error handling
1 parent 7382c42 commit 6f332c5

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed
 

‎src/rules/no-identical-title.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ export default createEslintRule<Options, MESSAGE_ID>({
5757
const title = getStringValue(argument)
5858

5959
if (vitestFnCall.type === 'test') {
60-
if (currentStack.testTitles.includes(title)) {
60+
if (currentStack?.testTitles.includes(title)) {
6161
context.report({
6262
node,
6363
messageId: 'multipleTestTitle'
6464
})
6565
}
66-
currentStack.testTitles.push(title)
66+
currentStack?.testTitles.push(title)
6767
}
6868

6969
if (vitestFnCall.type !== 'describe')

‎src/utils/validVitestFnCallChains.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,6 @@ export const ValidVitestFnCallChains = new Set([
10051005
'describe.runIf.sequential.each',
10061006
'describe.runIf.shuffle.each',
10071007
'describe.runIf.todo.each',
1008-
1009-
// Call chains that are not supported by Vitest, but were in the original list
1010-
// TODO(@veritem): Remove the use of these call chains in the test suite
10111008
'xtest',
10121009
'xtest.each',
10131010
'xit',

‎tests/no-identical-title.test.ts

+24-11
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,34 @@ import rule, { RULE_NAME } from '../src/rules/no-identical-title'
22
import { ruleTester } from './ruleTester'
33

44
ruleTester.run(RULE_NAME, rule, {
5-
valid: ['it(); it();', 'test("two", () => {});'],
6-
invalid: [
7-
{
8-
code: `describe('foo', () => {
5+
valid: [
6+
'it(); it();',
7+
'test("two", () => {});',
8+
`fdescribe('a describe', () => {
9+
test('a test', () => {
10+
expect(true).toBe(true);
11+
});
12+
});
13+
fdescribe('another describe', () => {
14+
test('a test', () => {
15+
expect(true).toBe(true);
16+
});
17+
});`
18+
],
19+
invalid: [
20+
{
21+
code: `describe('foo', () => {
922
it('works', () => {});
1023
it('works', () => {});
1124
});`,
12-
errors: [{ messageId: 'multipleTestTitle' }]
13-
},
14-
{
15-
code: `xdescribe('foo', () => {
25+
errors: [{ messageId: 'multipleTestTitle' }]
26+
},
27+
{
28+
code: `xdescribe('foo', () => {
1629
it('works', () => {});
1730
it('works', () => {});
1831
});`,
19-
errors: [{ messageId: 'multipleTestTitle' }]
20-
}
21-
]
32+
errors: [{ messageId: 'multipleTestTitle' }]
33+
}
34+
]
2235
})

0 commit comments

Comments
 (0)
Please sign in to comment.