mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-07 12:33:47 +08:00
- Update Sinon (breaking change does not affect us) - Update Mocha - Update Karma R=jacktfranklin@chromium.org Bug: none Change-Id: Ieb50ba55ce7a9e01e32ee553a6741e6323fcaaab Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3158223 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org> Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
"use strict";
|
|
|
|
var every = require("@sinonjs/commons").prototypes.array.every;
|
|
var concat = require("@sinonjs/commons").prototypes.array.concat;
|
|
var typeOf = require("@sinonjs/commons").typeOf;
|
|
|
|
var deepEqualFactory = require("../deep-equal").use;
|
|
|
|
var isMatcher = require("./is-matcher");
|
|
|
|
var keys = Object.keys;
|
|
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
|
|
|
/**
|
|
* Matches `actual` with `expectation`
|
|
*
|
|
* @private
|
|
* @param {*} actual A value to examine
|
|
* @param {object} expectation An object with properties to match on
|
|
* @param {object} matcher A matcher to use for comparison
|
|
* @returns {boolean} Returns true when `actual` matches all properties in `expectation`
|
|
*/
|
|
function matchObject(actual, expectation, matcher) {
|
|
var deepEqual = deepEqualFactory(matcher);
|
|
if (actual === null || actual === undefined) {
|
|
return false;
|
|
}
|
|
|
|
var expectedKeys = keys(expectation);
|
|
/* istanbul ignore else: cannot collect coverage for engine that doesn't support Symbol */
|
|
if (typeOf(getOwnPropertySymbols) === "function") {
|
|
expectedKeys = concat(expectedKeys, getOwnPropertySymbols(expectation));
|
|
}
|
|
|
|
return every(expectedKeys, function (key) {
|
|
var exp = expectation[key];
|
|
var act = actual[key];
|
|
|
|
if (isMatcher(exp)) {
|
|
if (!exp.test(act)) {
|
|
return false;
|
|
}
|
|
} else if (typeOf(exp) === "object") {
|
|
if (!matchObject(act, exp, matcher)) {
|
|
return false;
|
|
}
|
|
} else if (!deepEqual(act, exp)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
}
|
|
|
|
module.exports = matchObject;
|