如何在使用材料步进的角组件上编写单元测试
Angular应用使用模板中定义的材料步进。 该组件通过使用@viewchild('stepper')步进:Matstepper访问步进; 在组件中,许多方法基于单击事件设置所选索引。 单位测试失败,因为它说“无法设置未定义的属性(设置'SelectedIndex')”。
我认为步进器是在模板(IE HTML)中定义的,单位测试是在组件(.TS)上的,并且使用ViewChild访问它,因此在单位测试中无法访问步进,因为它未在组件中定义。
我如何编写具有材料步进的单元测试组件。
Angular app use material stepper that is defined in template.
The component access the stepper by using the @ViewChild('stepper') stepper: MatStepper;
In the component, many method set the selected index based on click event.
Unit test fail since it say "Cannot set properties of undefined (setting 'selectedIndex')".
I think stepper is defined in template(ie html), the unit test is on component(.ts) and used viewchild to access it so on unit test could not access stepper since it is not defined in component.
How do I write unit test component that has material stepper.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要确保已正确配置了测试床,并导入所有相关依赖项。在不查看代码的情况下,尝试使用以下方式尝试导入Matsteppermodule:
然后将其添加到您的测试中:
希望这会有所帮助。
You need to make sure that you have configured the TestBed correctly, and imported all relevant dependencies. Without seeing your code, try to import the MatStepperModule using:
and then add it to you TestBed:
Hope this helps.