MCPcopy Index your code
hub / github.com/angular/angular / matchObjectShape

Function matchObjectShape

packages/core/test/render3/matchers.ts:23–56  ·  view source on GitHub ↗
(
  name: string,
  shapePredicate: (obj: any) => obj is T,
  expected: Partial<T> = {},
)

Source from the content-addressed store, hash-verified

21 * @param expected Expected set of properties to be found on the object.
22 */
23export function matchObjectShape<T>(
24 name: string,
25 shapePredicate: (obj: any) => obj is T,
26 expected: Partial<T> = {},
27): jasmine.AsymmetricMatcher<T> {
28 const matcher = function () {};
29 let _actual: any = null;
30 let _matcherUtils: jasmine.MatchersUtil = null!;
31
32 matcher.asymmetricMatch = function (actual: any, matcherUtils: jasmine.MatchersUtil) {
33 _actual = actual;
34 _matcherUtils = matcherUtils;
35 if (!shapePredicate(actual)) return false;
36 for (const key in expected) {
37 if (expected.hasOwnProperty(key) && !matcherUtils.equals(actual[key], expected[key])) {
38 return false;
39 }
40 }
41 return true;
42 };
43 matcher.jasmineToString = function (pp: (value: any) => string) {
44 let errors: string[] = [];
45 if (!_actual || typeof _actual !== 'object') {
46 return `Expecting ${pp(expect)} got ${pp(_actual)}`;
47 }
48 for (const key in expected) {
49 if (expected.hasOwnProperty(key) && !_matcherUtils.equals(_actual[key], expected[key]))
50 errors.push(`\n property obj.${key} to equal ${expected[key]} but got ${_actual[key]}`);
51 }
52 return errors.join('\n');
53 };
54
55 return matcher;
56}
57
58/**
59 * Asymmetric matcher which matches a `TView` of a given shape.

Callers 5

matchMyShapeFunction · 0.90
matchTViewFunction · 0.85
matchTNodeFunction · 0.85
matchTI18nFunction · 0.85
matchTIcuFunction · 0.85

Calls 2

joinMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…