Search code examples
angularjasmineangular-test

angular 5 test static method of 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;

Solution

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