angular 5 测试组件的静态方法 [英] angular 5 test static method of component

查看:16
本文介绍了angular 5 测试组件的静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试的 Component 类上有一个静态方法,我的问题是如何在我的规范测试文件中访问该方法?

I have a static method on my Component class that I am testing, my question is how it is possible to access that method within my spec testing file?

到目前为止,我可以通过以下方式访问组件实例:

So far I can access a component instance with:

  let fixture = TestBed.createComponent(MyComponent);
  let comp = fixture.componentInstance;

推荐答案

静态方法不绑定到类的实例.所以这样的事情应该可以工作:MyComponent.nameOfStaticMethod(params)

Static methods are not bound to instances of classes. So something like this should work: MyComponent.nameOfStaticMethod(params)

这篇关于angular 5 测试组件的静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆