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

Function matchDomElement

packages/core/test/render3/matchers.ts:150–196  ·  view source on GitHub ↗
(
  expectedTagName: string | undefined = undefined,
  expectedAttrs: {[key: string]: string | null} = {},
)

Source from the content-addressed store, hash-verified

148 * @param expectedAttributes optional DOM element properties.
149 */
150export function matchDomElement(
151 expectedTagName: string | undefined = undefined,
152 expectedAttrs: {[key: string]: string | null} = {},
153): jasmine.AsymmetricMatcher<Element> {
154 const matcher = function () {};
155 let _actual: any = null;
156
157 matcher.asymmetricMatch = function (actual: any) {
158 _actual = actual;
159 if (!isDOMElement(actual)) return false;
160 if (expectedTagName && expectedTagName.toUpperCase() !== actual.tagName.toUpperCase()) {
161 return false;
162 }
163 if (expectedAttrs) {
164 for (const attrName in expectedAttrs) {
165 if (expectedAttrs.hasOwnProperty(attrName)) {
166 const expectedAttrValue = expectedAttrs[attrName];
167 const actualAttrValue = actual.getAttribute(attrName);
168 if (expectedAttrValue !== actualAttrValue) {
169 return false;
170 }
171 }
172 }
173 }
174 return true;
175 };
176 matcher.jasmineToString = function () {
177 let actualStr = isDOMElement(_actual)
178 ? `<${_actual.tagName}${toString(_actual.attributes)}>`
179 : JSON.stringify(_actual);
180 let expectedStr = `<${expectedTagName || '*'}${Object.entries(expectedAttrs).map(
181 ([key, value]) => ` ${key}=${JSON.stringify(value)}`,
182 )}>`;
183 return `[${actualStr} != ${expectedStr}]`;
184 };
185
186 function toString(attrs: NamedNodeMap) {
187 let text = '';
188 for (let i = 0; i < attrs.length; i++) {
189 const attr = attrs[i];
190 text += ` ${attr.name}=${JSON.stringify(attr.value)}`;
191 }
192 return text;
193 }
194
195 return matcher;
196}
197
198/**
199 * Asymmetric matcher which matches DOM text node.

Callers 1

matchers_spec.tsFile · 0.90

Calls 5

isDOMElementFunction · 0.90
mapMethod · 0.80
toStringFunction · 0.70
getAttributeMethod · 0.65
entriesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…