Skip to content

Commit

Permalink
chore(tests): update tests template name
Browse files Browse the repository at this point in the history
  • Loading branch information
iswilljr committed Dec 13, 2023
1 parent 3fce6d6 commit 852bb40
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ global.buildChallengeTestCases = <Args, Expected>({
}: BuildChallengeTestOptions<Args, Expected>) => {
const expectedTypeof = kindOf(cases[0].expected)

const name = fn?.name ?? spreadFn?.name

const executor = (args: Args) => {
if (fn) return fn(args)
if (spreadFn) return spreadFn(...(args as any))
Expand All @@ -21,7 +23,11 @@ global.buildChallengeTestCases = <Args, Expected>({
expect(kindOf(result)).toBe(expectedTypeof)
})

const nameTemplate = '#%# should return $expected when the input is $args'
const nameTemplate = spreadFn
? `#%# ${name}(${(cases[0].args as any[])
.map((_, i) => '$args.' + i)
.join(', ')}) should return $expected`
: `#%# ${name}($args) should return $expected`

it.each(cases)(nameTemplate, ({ args, expected }) => {
const result = executor(args)
Expand Down

0 comments on commit 852bb40

Please sign in to comment.