-
-
Notifications
You must be signed in to change notification settings - Fork 463
Open
Labels
enhancementNew feature or requestNew feature or request
Description
What is the problem this feature would solve?
It.each is essential part of testing and @effect/vitest would benefit by this addition.
https://vitest.dev/api/#test-each
Example:
test.each([
{ input: 'something', output: 'something else' }
]).effect("Should transform $input to $output", ({ input, output }) => Effect.gen(function *() {
const result = yield * someEffect(input);
expect(result).toBe(output);
}))What is the feature you are proposing to solve the problem?
Easier way of combining test cases to single test.
What alternatives have you considered?
There are workaround for this. One is describe.each, test each with wrapper.
describe.each([
{ input: 'something', output: 'something else' }
]).effect("Should transform $input to $output", ({ input, output }) => {
test.effect(`Should transform ${input} to ${output}`, Effect.gen(function *() {
const result = yield * someEffect(input);
expect(result).toBe(output);
}
}));
test.each([
[1, 2],
[2, 4],
[3, 6],
])("doubles %i to equal %i", async (input, expected) => {
const program = Effect.gen(function* () {
const result = yield* Effect.succeed(input * 2)
return result
})
const result = await Effect.runPromise(program)
expect(result).toBe(expected)
})
const testCases = [
{ input: 1, expected: 2 },
{ input: 2, expected: 4 },
{ input: 3, expected: 6 },
]
testCases.forEach(({ input, expected }) => {
V.it(`doubles ${input} to equal ${expected}`, () =>
Effect.gen(function* () {
const result = yield* Effect.succeed(input * 2)
expect(result).toBe(expected)
})
)
})
test.each([
{ input: 1, expected: 2 },
{ input: 2, expected: 4 },
{ input: 3, expected: 6 },
])("doubles $input to equal $expected", async ({ input, expected }) => {
const program = Effect.sync(() => input * 2)
const result = await Effect.runPromise(program)
expect(result).toBe(expected)
})f15uf15u
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request