【发布时间】:2019-10-19 02:49:34
【问题描述】:
尝试在 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 的 repo 中添加了更详细的解释,但它作为一个错误被拒绝了。链接:https://github.com/angular/angular/issues/30865#issue-452458779
【问题讨论】:
-
你有没有解决这个问题。如果是,请分享。
-
@siddiqrehman 我很乐意,但不幸的是没有。
-
为了变通,我没有使用TestBed创建组件,而是使用模拟渲染器2调用组件的构造函数并测试渲染器2逻辑。
-
@siddiqrehman 你能分享你的代码吗?
标签: angular unit-testing jestjs tdd bdd