effect icon indicating copy to clipboard operation
effect copied to clipboard

Vitest `it.{effect, live, scoped, scopedLive, flakyTest}.each` is not documented

Open rajzik opened this issue 1 month ago • 1 comments

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)
  })

rajzik avatar Dec 01 '25 08:12 rajzik

I think this needs to be renamed, as the functionality is present, only needs to be documented.

rajzik avatar Dec 11 '25 20:12 rajzik