尝试在Jest环境中模拟Renderer2,但无法使其正常工作。使用的是Jest 23和Angular 7。已经尝试了从以下链接中找到的所有内容:
- https://github.com/angular/angular/issues/15341
- Make the component test to have a body or mock Renderer2
component.ts
const icosahedron = document.getElementById('renderIcosahedron');
this.renderer2.appendChild(icosahedron, this.renderer.domElement);
一直收到错误信息(仅在测试中出现):
TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
编辑:Angular的存储库中已添加了更详细的说明,但被拒绝作为错误。链接:https://github.com/angular/angular/issues/30865#issue-452458779