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

Function toThrowExpectedRegExp

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

Source from the content-addressed store, hash-verified

143};
144
145const toThrowExpectedRegExp = (
146 matcherName: string,
147 options: MatcherHintOptions,
148 thrown: Thrown | null,
149 expected: RegExp,
150): SyncExpectationResult => {
151 const pass = thrown !== null && expected.test(thrown.message);
152
153 const message = pass
154 ? () =>
155 // eslint-disable-next-line prefer-template
156 matcherHint(matcherName, undefined, undefined, options) +
157 '\n\n' +
158 formatExpected('Expected pattern: not ', expected) +
159 (thrown !== null && thrown.hasMessage
160 ? formatReceived(
161 'Received message: ',
162 thrown,
163 'message',
164 expected,
165 ) + formatStack(thrown)
166 : formatReceived('Received value: ', thrown, 'value'))
167 : () =>
168 // eslint-disable-next-line prefer-template
169 matcherHint(matcherName, undefined, undefined, options) +
170 '\n\n' +
171 formatExpected('Expected pattern: ', expected) +
172 (thrown === null
173 ? `\n${DID_NOT_THROW}`
174 : thrown.hasMessage
175 ? formatReceived('Received message: ', thrown, 'message') +
176 formatStack(thrown)
177 : formatReceived('Received value: ', thrown, 'value'));
178
179 return {message, pass};
180};
181
182type AsymmetricMatcher = {
183 asymmetricMatch: (received: unknown) => boolean;

Callers 1

createMatcherFunction · 0.85

Calls 5

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

Tested by

no test coverage detected