{"id":"fbc69cb04949ad01","repo":"vitest-dev/vitest","slug":"matcherhint-tobeslowerthan-expects-the-actu","errorCode":null,"errorMessage":"${matcherHint('.toBeSlowerThan')} expects the actual value to be a benchmark result.","messagePattern":"(.+?) expects the actual value to be a benchmark result\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/integrations/chai/bench.ts","lineNumber":56,"sourceCode":"      message: () => {\n        const relation = ((actual.latency.mean - expected.latency.mean) / expected.latency.mean * 100).toFixed(2)\n        return pass\n          ? `${matcherHint('.not.toBeFasterThan')}\\n\\nExpected to not be faster, but was ${Math.abs(Number(relation))}% faster.\\n\\n`\n          + `Received: ${RECEIVED_COLOR(formatOps(actual.throughput.mean))} ops/sec\\n`\n          + `Expected: ${EXPECTED_COLOR(formatOps(expected.throughput.mean))} ops/sec\\n`\n          : `${matcherHint('.toBeFasterThan')}\\n\\nExpected to be faster${delta > 0 ? ` by at least ${(delta * 100).toFixed(0)}%` : ''}, but was ${Number(relation) > 0 ? `${relation}% slower` : `only ${Math.abs(Number(relation))}% faster`}.\\n\\n`\n            + `Received: ${RECEIVED_COLOR(formatOps(actual.throughput.mean))} ops/sec\\n`\n            + `Expected: ${EXPECTED_COLOR(formatOps(expected.throughput.mean))} ops/sec\\n`\n      },\n    }\n  },\n\n  toBeSlowerThan(actual: unknown, expected: unknown, options?: { delta?: number }) {\n    const { matcherHint, RECEIVED_COLOR, EXPECTED_COLOR } = this.utils\n    const delta = options?.delta ?? 0\n\n    if (!isBenchResult(actual)) {\n      throw new TypeError(\n        `${matcherHint('.toBeSlowerThan')} expects the actual value to be a benchmark result.`,\n      )\n    }\n    if (!isBenchResult(expected)) {\n      throw new TypeError(\n        `${matcherHint('.toBeSlowerThan')} expects the expected value to be a benchmark result.`,\n      )\n    }\n\n    const threshold = expected.latency.mean * (1 + delta)\n    const pass = actual.latency.mean > threshold\n\n    return {\n      pass,\n      message: () => {\n        const relation = ((actual.latency.mean - expected.latency.mean) / expected.latency.mean * 100).toFixed(2)\n        return pass\n          ? `${matcherHint('.not.toBeSlowerThan')}\\n\\nExpected to not be slower, but was ${relation}% slower.\\n\\n`","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/integrations/chai/bench.ts#L38-L74","documentation":"Thrown by the toBeSlowerThan benchmark matcher (same file, toBeFasterThan's sibling) when the actual value is not a BenchResult. Identical guard pattern: the matcher needs the actual to be a benchmark result with latency.mean so it can compare against the threshold derived from the expected baseline plus delta.","triggerScenarios":"expect(myValue).toBeSlowerThan(baseline) where myValue is a number, string, or non-bench object; using toBeSlowerThan in a regular it() block; passing the wall-clock time instead of the BenchResult.","commonSituations":"Confusing benchmark vs numeric matchers; refactoring a bench task so expect() no longer receives a BenchResult; copy-pasting toBeFasterThan usage without adjusting for the inverse semantics.","solutions":["Use toBeSlowerThan only inside a bench() task and pass the BenchResult to expect().","For numeric comparisons, use toBeGreaterThan.","Capture the result object from bench() and assert on it: expect(actualBenchResult).toBeSlowerThan(baselineBenchResult).","Confirm you are running the file under the benchmark mode (vitest bench) rather than the default test run."],"exampleFix":"// before\nexpect(150).toBeSlowerThan(baseline)\n\n// after\nexpect(actualBenchResult).toBeSlowerThan(baselineBenchResult, { delta: 0.1 })","handlingStrategy":"type-guard","validationCode":"function isBenchResult(value: unknown): value is { latency: { mean: number }; throughput: { mean: number } } {\n  return typeof value === 'object' && value !== null\n    && 'latency' in value && typeof (value as any).latency?.mean === 'number'\n}","typeGuard":"function isBenchResult(value: unknown): value is { latency: { mean: number }; throughput: { mean: number } } {\n  return typeof value === 'object' && value !== null\n    && 'latency' in value && typeof (value as any).latency?.mean === 'number'\n}","tryCatchPattern":null,"preventionTips":["Only call toBeSlowerThan inside bench() tasks where expect() receives a BenchResult.","Use toBeGreaterThan for plain numeric comparisons.","Run the spec under vitest bench (benchmark mode), not the default test run."],"tags":["benchmark","matcher","type-mismatch"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}