Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runner): describe/test name support anonymous function #3562

Merged
merged 2 commits into from Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/runner/src/suite.ts
Expand Up @@ -275,7 +275,7 @@ function createTest(fn: (
}

function formatName(name: string | Function) {
return typeof name === 'string' ? name : name instanceof Function ? name.name : String(name)
return typeof name === 'string' ? name : name instanceof Function ? (name.name || 'Anonymous') : String(name)
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved
}

function formatTitle(template: string, items: any[], idx: number) {
Expand Down
12 changes: 12 additions & 0 deletions test/reporters/fixtures/function-as-name.test.ts
Expand Up @@ -15,6 +15,18 @@ describe(Bar, () => {
})
})

describe(() => {}, () => {
test(foo, () => {
expect(0).toBe(0)
})
})

describe(foo, () => {
test(() => {}, () => {
expect(0).toBe(0)
})
})

describe.each([1])(foo, () => {
test.each([1])(foo, () => {
expect(0).toBe(0)
Expand Down
2 changes: 2 additions & 0 deletions test/reporters/tests/function-as-name.test.ts
Expand Up @@ -9,6 +9,8 @@ test('should print function name', async () => {
expect(stdout).toBeTruthy()
expect(stdout).toContain('function-as-name.test.ts > foo > Bar')
expect(stdout).toContain('function-as-name.test.ts > Bar > foo')
expect(stdout).toContain('function-as-name.test.ts > Anonymous > foo')
expect(stdout).toContain('function-as-name.test.ts > foo > Anonymous')
expect(stdout).toContain('function-as-name.test.ts > foo > foo')
expect(stdout).toContain('function-as-name.test.ts > Bar > Bar')
})