{"record":{"id":"774b4358b1daccfc","repo":"ruvnet/ruflo","slug":"expected-error-to-be-instance-of-errorclass-name","errorCode":null,"errorMessage":"Expected error to be instance of ${ErrorClass.name}, but got ${(error as Error).constructor.name}","messagePattern":"Expected error to be instance of (.+?), but got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/testing/src/helpers/test-utils.ts","lineNumber":611,"sourceCode":"/**\n * Assert that a promise rejects with a specific error type\n *\n * @example\n * await expectToReject(\n *   async () => await riskyOperation(),\n *   ValidationError\n * );\n */\nexport async function expectToReject<T extends Error>(\n  operation: () => Promise<unknown>,\n  ErrorClass?: new (...args: unknown[]) => T\n): Promise<T> {\n  try {\n    await operation();\n    throw new Error('Expected operation to reject, but it resolved');\n  } catch (error) {\n    if (ErrorClass && !(error instanceof ErrorClass)) {\n      throw new Error(\n        `Expected error to be instance of ${ErrorClass.name}, but got ${(error as Error).constructor.name}`\n      );\n    }\n    return error as T;\n  }\n}\n\n/**\n * Create a mock function with tracking capabilities\n */\nexport function createTrackedMock<T extends (...args: unknown[]) => unknown>(\n  implementation?: T\n): TrackedMock<T> {\n  // Use type assertion to handle the optional implementation\n  const mock = implementation ? vi.fn(implementation) : vi.fn();\n  const calls: Array<{ args: Parameters<T>; result?: ReturnType<T>; error?: Error; duration: number }> = [];\n\n  const tracked = ((...args: Parameters<T>) => {","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/testing/src/helpers/test-utils.ts#L593-L629","documentation":"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.","triggerScenarios":"Thrown at v3/@claude-flow/testing/src/helpers/test-utils.ts:611 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}