MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / _assertContains

Method _assertContains

lib/helper/JSONResponse.js:344–371  ·  view source on GitHub ↗
(actual, expected)

Source from the content-addressed store, hash-verified

342 }
343
344 _assertContains(actual, expected) {
345 for (const key in expected) {
346 assert(key in actual, `Key "${key}" not found in ${JSON.stringify(actual)}`)
347 if (typeof expected[key] === 'object' && expected[key] !== null) {
348 if (Array.isArray(expected[key])) {
349 // Handle array comparison: each expected element should have a match in actual array
350 assert(Array.isArray(actual[key]), `Expected array for key "${key}", but got ${typeof actual[key]}`)
351 for (const expectedItem of expected[key]) {
352 let found = false
353 for (const actualItem of actual[key]) {
354 try {
355 this._assertContains(actualItem, expectedItem)
356 found = true
357 break
358 } catch (err) {
359 continue
360 }
361 }
362 assert(found, `No matching element found in array for ${JSON.stringify(expectedItem)}`)
363 }
364 } else {
365 this._assertContains(actual[key], expected[key])
366 }
367 } else {
368 assert.deepStrictEqual(actual[key], expected[key], `Values for key "${key}" don't match`)
369 }
370 }
371 }
372}
373
374export { JSONResponse, JSONResponse as default }

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected