MCPcopy Create free account
hub / github.com/ampproject/amphtml / expectContext

Function expectContext

test/unit/core/context/test-node-discover.js:103–133  ·  view source on GitHub ↗
(nodeOrContext, spec)

Source from the content-addressed store, hash-verified

101 }
102
103 function expectContext(nodeOrContext, spec) {
104 const contextNode = nodeOrContext.nodeType
105 ? ContextNode.get(nodeOrContext)
106 : nodeOrContext;
107 if (spec.isRoot !== undefined) {
108 expect(contextNode.isRoot, 'isRoot').to.equal(spec.isRoot);
109 }
110 if (spec.root !== undefined) {
111 const {root} = contextNode;
112 expect((root && root.node) ?? null, 'root').to.equal(spec.root);
113 }
114 if (spec.discoverable !== undefined) {
115 expect(contextNode.isDiscoverable(), 'discoverable').to.equal(
116 spec.discoverable
117 );
118 }
119 if (spec.parent !== undefined) {
120 const {parent} = contextNode;
121 const parentNode = (parent && parent.node) ?? null;
122 const specNode =
123 ((spec.parent && spec.parent.node) || spec.parent) ?? null;
124 expect(parentNode, 'parent').to.equal(specNode);
125 }
126 if (spec.children !== undefined) {
127 const children = (contextNode.children || []).map((cn) => cn.node || cn);
128 children.sort(domOrderComparator);
129 const specChildren = spec.children.slice(0);
130 specChildren.sort(domOrderComparator);
131 expect(children, 'children').to.deep.equal(specChildren);
132 }
133 }
134
135 describe('ContextNode.get', () => {
136 it('should create an element node', () => {

Callers 1

Calls 3

expectFunction · 0.85
isDiscoverableMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected