ruvnet/ruflo · error
Expected error to be instance of ${ErrorClass.name}, but got
Error message
Expected error to be instance of ${ErrorClass.name}, but got ${(error as Error).constructor.name} What it means
expectToReject caught the rejection but the error's constructor did not match the expected ErrorClass. The operation did reject, just with the wrong error type — the message names both the expected and actual class so the mismatch is obvious.
Source
Thrown at v3/@claude-flow/testing/src/helpers/test-utils.ts:611
/**
* 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();
const calls: Array<{ args: Parameters<T>; result?: ReturnType<T>; error?: Error; duration: number }> = [];
const tracked = ((...args: Parameters<T>) => {View on GitHub (pinned to fa13ee4ad6)
Solutions
- Assert against the actual error class thrown, or fix the code to throw the expected class.
- Wrap foreign errors in the expected error type at the boundary.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at v3/@claude-flow/testing/src/helpers/test-utils.ts:611 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/774b4358b1daccfc.
Report an issue: GitHub.