Skip to content

test.each: Support formatting for variable number of arguments #9737

Closed
@l-abels

Description

@l-abels

🚀 Feature Proposal

Allow the test.each test name to format inputs of variable length cleanly. Allow for the previous behavior to be re-enabled or add a special operator that uses Array.join() behind the scenes.

Motivation

test.each can support inputs of varying length if the test function makes the uses of the spread operator (...). However, there's no good way to format the test name such that each test includes all of the arguments. #6342 disabled the default util.inspect behavior that would have allowed for this.

Example

Proposal 1:

 it.todo.each ([
    ['Red', 'Blue'],
    ['Purple', 'Yellow', 'Green'],
  ]) ('Looks good with the following colors: ');
Looks good with the following colors: Red Blue
Looks good with the following colors: Purple Yellow Green

Proposal 2:

 it.todo.each ([
    ['Garlic', 'Smashed', 'Chopped'],
    ['Beef', 'Sliced', 'Salted', 'Grilled'],
  ]) ('%s can be prepared in the order %a{ -> }');
Garlic can be prepared in the order Smashed -> Chopped
Beef can be prepared in the order Sliced -> Salted -> Grilled

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions