MCPcopy
hub / github.com/jestjs/jest / toThrowExpectedAsymmetric

Function toThrowExpectedAsymmetric

packages/expect/src/toThrowMatchers.ts:186–221  ·  view source on GitHub ↗
(
  matcherName: string,
  options: MatcherHintOptions,
  thrown: Thrown | null,
  expected: AsymmetricMatcher,
)

Source from the content-addressed store, hash-verified

184};
185
186const toThrowExpectedAsymmetric = (
187 matcherName: string,
188 options: MatcherHintOptions,
189 thrown: Thrown | null,
190 expected: AsymmetricMatcher,
191): SyncExpectationResult => {
192 const pass = thrown !== null && expected.asymmetricMatch(thrown.value);
193
194 const message = pass
195 ? () =>
196 // eslint-disable-next-line prefer-template
197 matcherHint(matcherName, undefined, undefined, options) +
198 '\n\n' +
199 formatExpected('Expected asymmetric matcher: not ', expected) +
200 '\n' +
201 (thrown !== null && thrown.hasMessage
202 ? formatReceived('Received name: ', thrown, 'name') +
203 formatReceived('Received message: ', thrown, 'message') +
204 formatStack(thrown)
205 : formatReceived('Thrown value: ', thrown, 'value'))
206 : () =>
207 // eslint-disable-next-line prefer-template
208 matcherHint(matcherName, undefined, undefined, options) +
209 '\n\n' +
210 formatExpected('Expected asymmetric matcher: ', expected) +
211 '\n' +
212 (thrown === null
213 ? DID_NOT_THROW
214 : thrown.hasMessage
215 ? formatReceived('Received name: ', thrown, 'name') +
216 formatReceived('Received message: ', thrown, 'message') +
217 formatStack(thrown)
218 : formatReceived('Thrown value: ', thrown, 'value'));
219
220 return {message, pass};
221};
222
223const toThrowExpectedObject = (
224 matcherName: string,

Callers 1

createMatcherFunction · 0.85

Calls 5

matcherHintFunction · 0.90
formatExpectedFunction · 0.85
formatReceivedFunction · 0.85
formatStackFunction · 0.85
asymmetricMatchMethod · 0.45

Tested by

no test coverage detected