Skip to content

oneOf

oneOf<T>(…arbitraries): Dependent<TypeOfArbitraries<T>>

It generates an integer between 0 and the number of arbitraries passed in, and then generates a value from the corresponding arbitrary.

Example

random(oneOf(object({foo: string()}), object({bar: string()})))
// => {foo: "bar"}
random(oneOf(object({foo: string()}), object({bar: string()})))
// => {bar: "foo"}

Type Parameters

T extends Arbitrary<unknown>[]

Parameters

arbitraries

…[...T[]]

The arbitraries to select one of.

Returns

Dependent<TypeOfArbitraries<T>>

An arbitrary that is randomly chosen from the list.