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

Method _addSnapshot

packages/jest-snapshot/src/State.ts:111–136  ·  view source on GitHub ↗
(
    key: string,
    receivedSerialized: string,
    options: {isInline: boolean; error?: Error},
  )

Source from the content-addressed store, hash-verified

109 }
110
111 private _addSnapshot(
112 key: string,
113 receivedSerialized: string,
114 options: {isInline: boolean; error?: Error},
115 ): void {
116 this._dirty = true;
117 if (options.isInline) {
118 // eslint-disable-next-line unicorn/error-message
119 const error = options.error || new Error();
120 const lines = getStackTraceLines(
121 removeLinesBeforeExternalMatcherTrap(error.stack || ''),
122 );
123 const frame = getTopFrame(lines);
124 if (!frame) {
125 throw new Error(
126 "Jest: Couldn't infer stack frame for inline snapshot.",
127 );
128 }
129 this._inlineSnapshots.push({
130 frame,
131 snapshot: receivedSerialized,
132 });
133 } else {
134 this._snapshotData[key] = receivedSerialized;
135 }
136 }
137
138 clear(): void {
139 this._snapshotData = this._initialData;

Callers 1

matchMethod · 0.95

Calls 3

getStackTraceLinesFunction · 0.90
getTopFrameFunction · 0.90

Tested by

no test coverage detected