MCPcopy
hub / github.com/digitalbazaar/jsonld.js / comparePartialEvents

Function comparePartialEvents

tests/misc.js:517–537  ·  view source on GitHub ↗
(source, target, path = [])

Source from the content-addressed store, hash-verified

515 // for each source, only check fields present in target
516 // allows easier checking of just a few key fields
517 function comparePartialEvents(source, target, path = []) {
518 if(Array.isArray(source)) {
519 assert(Array.isArray(target),
520 `target not an array, path: ${JSON.stringify(path)}`);
521 assert.equal(source.length, target.length,
522 `event arrays size mismatch: ${JSON.stringify(path)}`);
523 for(let i = 0; i < source.length; ++i) {
524 comparePartialEvents(source[i], target[i], [...path, i]);
525 }
526 } else if(isObject(target)) {
527 // check all target keys recursively
528 for(const key of Object.keys(target)) {
529 assert(key in source,
530 `missing expected key: "${key}", path: ${JSON.stringify(path)}`);
531 comparePartialEvents(source[key], target[key], [...path, key]);
532 }
533 } else {
534 assert.deepStrictEqual(source, target,
535 `not equal, path: ${JSON.stringify(path)}`);
536 }
537 }
538
539 // test different apis
540 // use appropriate options

Callers 2

_testFunction · 0.85
misc.jsFile · 0.85

Calls 2

assertFunction · 0.85
isObjectFunction · 0.85

Tested by

no test coverage detected