{"record":{"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/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/integrations/chai/bench.ts#L38-L74","documentation":"The .toBeSlowerThan benchmark matcher is the inverse of toBeFasterThan. It validates that the actual (received) value is a BenchResult (object with latency.mean number). If the actual side fails isBenchResult, this TypeError fires before any comparison is attempted.","triggerScenarios":"Calling expect(value).toBeSlowerThan(other) where `value` is not a bench result — a raw number, string, or object without the latency structure.","commonSituations":"Using toBeSlowerThan outside of a bench() context; passing the wrong variable as actual; comparing raw timing values.","solutions":["Ensure the actual value is the BenchResult object from a bench() task.","Use toBeGreaterThan for raw numeric comparisons instead of the bench matcher.","Confirm the object shape has `latency.mean` as a number before asserting."],"exampleFix":"// before:\nexpect(200).toBeSlowerThan(baseline)\n\n// after:\nexpect(myBenchResult).toBeSlowerThan(baselineBenchResult)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isBenchResult(v: unknown): v is { latency: { mean: number }; throughput: { mean: number } } {\n  return typeof v === 'object' && v !== null\n    && 'latency' in v && typeof (v as any).latency?.mean === 'number'\n}","tryCatchPattern":null,"preventionTips":["Only use toBeSlowerThan with bench result objects from bench() tasks.","Use toBeGreaterThan for raw numeric comparisons."],"tags":["bench","matcher","type-validation"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}