Skip to content

Support sets as argument to expect.toBeOneOf #8902

@tim-we

Description

@tim-we

Clear and concise description of the problem

In Vitest tests you can do this:

expect('b').toBeOneOf(['a','b','c','d']);

but not this:

const values = new Set(['a','b','c','d']);
expect('b').toBeOneOf(values);

You get this error: TypeError: You must provide an array to expect(received).toBeOneOf(expected), not 'object'.

Suggested solution

I think toBeOneOf is a classic Set operation and I think Vitest should support it. I think the implementation should be very straightforward and I am happy to provide a PR for it.

Alternative

There are simple workarounds of course, as you can just do this:

expect('b').toBeOneOf([...values]);

(I had to do this at work recently)
But I don't see a reason why Vitest should not just support this out of the box.

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions