diff --git a/libs/ng-mocks/src/lib/mock-helper/crawl/el-def-get-parent.ts b/libs/ng-mocks/src/lib/mock-helper/crawl/el-def-get-parent.ts index ec141ccc9f..bb48717569 100644 --- a/libs/ng-mocks/src/lib/mock-helper/crawl/el-def-get-parent.ts +++ b/libs/ng-mocks/src/lib/mock-helper/crawl/el-def-get-parent.ts @@ -15,24 +15,32 @@ const getVcr = (node: any, child: any): undefined | ViewContainerRef => { return coreInjector(ViewContainerRef, child.injector); }; +const getScanViewRefRootNodes = (node: any, child: any): Array<[number, any]> => { + const vcr = getVcr(node, child); + if (!vcr) { + return []; + } + + const result: Array<[number, any]> = []; + for (let vrIndex = 0; vrIndex < vcr.length; vrIndex += 1) { + const vr = vcr.get(vrIndex); + for (let rnIndex = 0; rnIndex < (vr as any).rootNodes.length; rnIndex += 1) { + result.push([rnIndex, (vr as any).rootNodes[rnIndex]]); + } + } + + return result; +}; + const scanViewRef = (node: DebugElement) => { let result: any; let index: any; for (const child of node.parent?.childNodes || []) { - const vcr = getVcr(node, child); - if (!vcr) { - continue; - } - - for (let vrIndex = 0; vrIndex < vcr.length; vrIndex += 1) { - const vr = vcr.get(vrIndex); - for (let rnIndex = 0; rnIndex < (vr as any).rootNodes.length; rnIndex += 1) { - const rootNode = (vr as any).rootNodes[rnIndex]; - if (rootNode === node.nativeNode && (index === undefined || rnIndex < index)) { - result = elDefGetNode(child); - index = rnIndex; - } + for (const [rnIndex, rootNode] of getScanViewRefRootNodes(node, child)) { + if (rootNode === node.nativeNode && (index === undefined || rnIndex < index)) { + result = elDefGetNode(child); + index = rnIndex; } } } diff --git a/libs/ng-mocks/src/lib/mock-helper/mock-helper.format-html.ts b/libs/ng-mocks/src/lib/mock-helper/mock-helper.format-html.ts index 201161319c..3ea9516c5d 100644 --- a/libs/ng-mocks/src/lib/mock-helper/mock-helper.format-html.ts +++ b/libs/ng-mocks/src/lib/mock-helper/mock-helper.format-html.ts @@ -40,9 +40,6 @@ const handleArray = (formatCallback: any, html: any) => { }; const handlePrimitives = (formatCallback: any, html: any, outer: boolean) => { - if (typeof html === 'string' || html === undefined) { - return normalizeHtml(html); - } if (Array.isArray(html)) { return handleArray(formatCallback, html); } @@ -61,6 +58,7 @@ const handlePrimitives = (formatCallback: any, html: any, outer: boolean) => { const format = ( html: + | undefined | string | HTMLElement | Text @@ -73,6 +71,10 @@ const format = ( | Array<{ nativeNode: any } | { nativeElement: any } | { debugElement: any }>, outer = false, ): string => { + if (typeof html === 'string' || html === undefined) { + return normalizeHtml(html); + } + const result = handlePrimitives(format, html, outer); if (result !== undefined) { return result;