{"record":{"id":"22e78e909b445919","repo":"vitest-dev/vitest","slug":"matcherhint-tobeslowerthan-expects-the-expe","errorCode":null,"errorMessage":"${matcherHint('.toBeSlowerThan')} expects the expected value to be a benchmark result.","messagePattern":"(.+?) expects the expected value to be a benchmark result\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/integrations/chai/bench.ts","lineNumber":61,"sourceCode":"          + `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`\n          + `Received: ${RECEIVED_COLOR(formatOps(actual.throughput.mean))} ops/sec\\n`\n          + `Expected: ${EXPECTED_COLOR(formatOps(expected.throughput.mean))} ops/sec\\n`\n          : `${matcherHint('.toBeSlowerThan')}\\n\\nExpected to be slower${delta > 0 ? ` by at least ${(delta * 100).toFixed(0)}%` : ''}, but was ${Number(relation) < 0 ? `${Math.abs(Number(relation))}% faster` : `only ${relation}% slower`}.\\n\\n`\n            + `Received: ${RECEIVED_COLOR(formatOps(actual.throughput.mean))} ops/sec\\n`\n            + `Expected: ${EXPECTED_COLOR(formatOps(expected.throughput.mean))} ops/sec\\n`","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/integrations/chai/bench.ts#L43-L79","documentation":"Same .toBeSlowerThan matcher, second-argument check. Fires when the actual is a valid BenchResult but the expected (second argument) is not. The matcher needs expected.latency.mean to compute the slowness threshold.","triggerScenarios":"Calling expect(benchResult).toBeSlowerThan(notABenchResult) where the second argument lacks the latency structure.","commonSituations":"Passing a raw number or plain object as the expected baseline instead of a bench result; misunderstanding that both arguments must be BenchResult objects.","solutions":["Pass a full BenchResult as the second argument.","Use options.delta for a percentage-based threshold rather than a raw number.","Validate the second argument has `latency.mean` before calling the matcher."],"exampleFix":"// before:\nexpect(result).toBeSlowerThan(100)\n\n// after:\nexpect(result).toBeSlowerThan(baselineResult, { delta: 0.1 })","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":["Pass a second bench result as the expected argument.","Use options.delta for percentage thresholds instead of raw numbers."],"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"}