From e08c45c3921ab1c517021836bc73a13f1310c538 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Fri, 28 Aug 2026 10:19:14 -0700 Subject: [PATCH] perf(expect): lazily format spy matcher failures (#11090) Co-authored-by: Codex --- packages/expect/src/jest-expect.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/expect/src/jest-expect.ts b/packages/expect/src/jest-expect.ts index 920813d83..22fc3b17a 100644 --- a/packages/expect/src/jest-expect.ts +++ b/packages/expect/src/jest-expect.ts @@ -608,14 +608,13 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => { const pass = spy.mock.calls.some(callArg => equalsArgumentArray(callArg, args)) const isNot = utils.flag(this, 'negate') as boolean - const msg = utils.getMessage(this, [ - pass, - `expected "${spyName}" to be called with arguments: #{exp}`, - `expected "${spyName}" to not be called with arguments: #{exp}`, - args, - ]) - if ((pass && isNot) || (!pass && !isNot)) { + const msg = utils.getMessage(this, [ + pass, + `expected "${spyName}" to be called with arguments: #{exp}`, + `expected "${spyName}" to not be called with arguments: #{exp}`, + args, + ]) throw new AssertionError(formatCalls(spy, msg, args)) } }) @@ -627,14 +626,13 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => { const pass = hasCallWithArgs && callCount === 1 const isNot = utils.flag(this, 'negate') as boolean - const msg = utils.getMessage(this, [ - pass, - `expected "${spyName}" to be called once with arguments: #{exp}`, - `expected "${spyName}" to not be called once with arguments: #{exp}`, - args, - ]) - if ((pass && isNot) || (!pass && !isNot)) { + const msg = utils.getMessage(this, [ + pass, + `expected "${spyName}" to be called once with arguments: #{exp}`, + `expected "${spyName}" to not be called once with arguments: #{exp}`, + args, + ]) throw new AssertionError(formatCalls(spy, msg, args)) } }) -- 2.51.2