Effect CommunityEC
Effect Community7mo ago
2 replies
Kyrre Gjerstad

extracting only error message in tests

Hi, i'm trying to improve the error messages in my test. I'm not really interested in the full Effect error stack, just the formatted error.

something like

error: "Expected { readonly errors: ReadonlyArray<Error>; readonly data: DataType }, actual null",


but returning return Effect.fail gives me the whole trace which is very noisy in this case. Any suggestions?

it.each(testCases)(
  '$methodName - $description',
  async ({ method }) => {
    const program = Effect.gen(function* () {
      const service = yield* Service;
      return yield* method(service);
    }).pipe(
      Effect.catchTags({
        ParseError: (error) => {
          const formattedError = ParseResult.TreeFormatter.formatErrorSync(error);
          return Effect.fail(formattedError);
        },
      })
    );

    await TestingRuntime.runPromise(program);
  }
);
Was this page helpful?