(config: MatchSnapshotConfig)
| 275 | }; |
| 276 | |
| 277 | const _toMatchSnapshot = (config: MatchSnapshotConfig) => { |
| 278 | const {context, hint, inlineSnapshot, isInline, matcherName, properties} = |
| 279 | config; |
| 280 | let {received} = config; |
| 281 | |
| 282 | /** If a test was ran with `test.failing`. Passed by Jest Circus. */ |
| 283 | const {testFailing = false} = context; |
| 284 | |
| 285 | if (!testFailing && context.dontThrow) { |
| 286 | // Suppress errors while running tests |
| 287 | context.dontThrow(); |
| 288 | } |
| 289 | |
| 290 | const {currentConcurrentTestName, isNot, snapshotState} = context; |
| 291 | const currentTestName = |
| 292 | currentConcurrentTestName?.() ?? context.currentTestName; |
| 293 | |
| 294 | if (isNot) { |
| 295 | throw new Error( |
| 296 | matcherErrorMessage( |
| 297 | matcherHintFromConfig(config, false), |
| 298 | NOT_SNAPSHOT_MATCHERS, |
| 299 | ), |
| 300 | ); |
| 301 | } |
| 302 | |
| 303 | if (snapshotState == null) { |
| 304 | // Because the state is the problem, this is not a matcher error. |
| 305 | // Call generic stringify from jest-matcher-utils package |
| 306 | // because uninitialized snapshot state does not need snapshot serializers. |
| 307 | throw new Error( |
| 308 | `${matcherHintFromConfig(config, false)}\n\n` + |
| 309 | 'Snapshot state must be initialized' + |
| 310 | `\n\n${printWithType('Snapshot state', snapshotState, stringify)}`, |
| 311 | ); |
| 312 | } |
| 313 | |
| 314 | const fullTestName = |
| 315 | currentTestName && hint |
| 316 | ? `${currentTestName}: ${hint}` |
| 317 | : currentTestName || ''; // future BREAKING change: || hint |
| 318 | |
| 319 | if (typeof properties === 'object') { |
| 320 | if (typeof received !== 'object' || received === null) { |
| 321 | throw new Error( |
| 322 | matcherErrorMessage( |
| 323 | matcherHintFromConfig(config, false), |
| 324 | `${RECEIVED_COLOR( |
| 325 | 'received', |
| 326 | )} value must be an object when the matcher has ${EXPECTED_COLOR( |
| 327 | 'properties', |
| 328 | )}`, |
| 329 | printWithType('Received', received, printReceived), |
| 330 | ), |
| 331 | ); |
| 332 | } |
| 333 | |
| 334 | const propertyPass = context.equals(received, properties, [ |
no test coverage detected