Skip to content

Commit 3d43638

Browse files
authoredJun 15, 2023
feat(runner): describe/test name support anonymous function (#3562)
1 parent bc49bac commit 3d43638

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
 

‎packages/runner/src/suite.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function createTest(fn: (
269269
}
270270

271271
function formatName(name: string | Function) {
272-
return typeof name === 'string' ? name : name instanceof Function ? name.name : String(name)
272+
return typeof name === 'string' ? name : name instanceof Function ? (name.name || '<anonymous>') : String(name)
273273
}
274274

275275
function formatTitle(template: string, items: any[], idx: number) {

‎test/reporters/fixtures/function-as-name.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ describe(Bar, () => {
1515
})
1616
})
1717

18+
describe(() => {}, () => {
19+
test(foo, () => {
20+
expect(0).toBe(0)
21+
})
22+
})
23+
24+
describe(foo, () => {
25+
test(() => {}, () => {
26+
expect(0).toBe(0)
27+
})
28+
})
29+
1830
describe.each([1])(foo, () => {
1931
test.each([1])(foo, () => {
2032
expect(0).toBe(0)

‎test/reporters/tests/function-as-name.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ test('should print function name', async () => {
99
expect(stdout).toBeTruthy()
1010
expect(stdout).toContain('function-as-name.test.ts > foo > Bar')
1111
expect(stdout).toContain('function-as-name.test.ts > Bar > foo')
12+
expect(stdout).toContain('function-as-name.test.ts > <anonymous> > foo')
13+
expect(stdout).toContain('function-as-name.test.ts > foo > <anonymous>')
1214
expect(stdout).toContain('function-as-name.test.ts > foo > foo')
1315
expect(stdout).toContain('function-as-name.test.ts > Bar > Bar')
1416
})

0 commit comments

Comments
 (0)
Please sign in to comment.