function compareSubset(expected, actual) {
  if (expected === actual) {
    return true;
  }
  if (typeof actual !== typeof expected) {
    return false;
  }
  if (typeof expected !== 'object' || expected === null) {
    return expected === actual;
  }
  if (!actual) {
    return false;
  }

  if (Array.isArray(expected)) {
    if (!Array.isArray(actual)) {
      return false;
    }
    return expected.every(function (exp) {
      return actual.some(function (act) {
        return compareSubset(exp, act);
      });
    });
  }

  if (expected instanceof Date) {
    if (actual instanceof Date) {
      return expected.getTime() === actual.getTime();
    } else {
      return false;
    }
  }

  return Object.keys(expected).every(function (key) {
    let expectedValue = expected[key];
    let actualValue = actual[key];
    if (
      typeof expectedValue === 'object' &&
      expectedValue !== null &&
      actualValue !== null
    ) {
      return compareSubset(expectedValue, actualValue);
    }
    if (typeof expectedValue === 'function') {
      return expectedValue(actualValue);
    }
    return actualValue === expectedValue;
  });
}
A subset-aware compare function

@param {unknown} expected
@param {unknown} actual
@returns {boolean}