ruvnet/ruflo · error

Expected operation to reject, but it resolved

Error message

Expected operation to reject, but it resolved

What it means

expectToReject ran the operation and it resolved successfully instead of rejecting. The assertion utility then throws this sentinel error to fail the test: the point is that the operation was expected to fail, so success is the failure condition.

Source

Thrown at v3/@claude-flow/testing/src/helpers/test-utils.ts:608

  keys(): string[];
}

/**
 * Assert that a promise rejects with a specific error type
 *
 * @example
 * await expectToReject(
 *   async () => await riskyOperation(),
 *   ValidationError
 * );
 */
export async function expectToReject<T extends Error>(
  operation: () => Promise<unknown>,
  ErrorClass?: new (...args: unknown[]) => T
): Promise<T> {
  try {
    await operation();
    throw new Error('Expected operation to reject, but it resolved');
  } catch (error) {
    if (ErrorClass && !(error instanceof ErrorClass)) {
      throw new Error(
        `Expected error to be instance of ${ErrorClass.name}, but got ${(error as Error).constructor.name}`
      );
    }
    return error as T;
  }
}

/**
 * Create a mock function with tracking capabilities
 */
export function createTrackedMock<T extends (...args: unknown[]) => unknown>(
  implementation?: T
): TrackedMock<T> {
  // Use type assertion to handle the optional implementation
  const mock = implementation ? vi.fn(implementation) : vi.fn();

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Fix the operation so it rejects under the tested failure condition.
  2. Check the test setup actually triggers the failure path.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at v3/@claude-flow/testing/src/helpers/test-utils.ts:608 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/cc3998fb57c143c6. Report an issue: GitHub.