MCPcopy
hub / github.com/vitest-dev/vitest / match

Method match

packages/snapshot/src/client.ts:123–199  ·  view source on GitHub ↗
(options: AssertOptions)

Source from the content-addressed store, hash-verified

121 }
122
123 match(options: AssertOptions): MatchResult {
124 const {
125 filepath,
126 name,
127 testId = name,
128 message,
129 isInline = false,
130 properties,
131 inlineSnapshot,
132 error,
133 errorMessage,
134 rawSnapshot,
135 assertionName,
136 } = options
137 let { received } = options
138
139 if (!filepath) {
140 throw new Error('Snapshot cannot be used outside of test')
141 }
142
143 const snapshotState = this.getSnapshotState(filepath)
144 const testName = [name, ...(message ? [message] : [])].join(' > ')
145
146 // Probe first so we can mark as checked even on early return
147 const expectedSnapshot = snapshotState.probeExpectedSnapshot({
148 testName,
149 testId,
150 isInline,
151 inlineSnapshot,
152 })
153
154 if (typeof properties === 'object') {
155 if (typeof received !== 'object' || !received) {
156 expectedSnapshot.markAsChecked()
157 throw new Error(
158 'Received value must be an object when the matcher has properties',
159 )
160 }
161
162 let propertiesPass: boolean
163 try {
164 propertiesPass = this.options.isEqual?.(received, properties) ?? false
165 }
166 catch (err) {
167 expectedSnapshot.markAsChecked()
168 throw err
169 }
170 if (!propertiesPass) {
171 expectedSnapshot.markAsChecked()
172 return {
173 pass: false,
174 message: () => errorMessage || 'Snapshot properties mismatched',
175 actual: received,
176 expected: properties,
177 }
178 }
179 received = deepMergeSnapshot(received, properties)
180 }

Callers 15

assertMethod · 0.95
parseRegexpFunction · 0.45
BrowserTestRunnerClass · 0.45
minIndentFunction · 0.45
parseSingleV8StackFunction · 0.45
parseStacktraceFunction · 0.45
shouldFilterFunction · 0.45
formatTitleFunction · 0.45
getUsedPropsFunction · 0.45
traverseSuiteFunction · 0.45
getSourcesMethod · 0.45

Calls 3

getSnapshotStateMethod · 0.95
deepMergeSnapshotFunction · 0.90
probeExpectedSnapshotMethod · 0.80

Tested by 2

extractLogsFunction · 0.36
matchJunitTimeFunction · 0.36