Check out a method that calls another method from viewChild using Jasmine

I have this method that checks the component and calls this other component, which is ViewChild. I am using a component, using this.ViewChildComponent.someMethod();in a component that I am trying to test. I tried to use spyOn(viewChildComponent, 'someMethod').and.returnValue(true). But he says this.ViewChildComponent.someMethod() is undefined. I have all the dependencies, such as services ViewChildComponentfor vendors. I even took a step forward and made a call, which ViewChildComponentmakes a decision for its maintenancesomeMethod();

Any help would be awesome.

+4
source share
1 answer

if you have for example

class TestedComponent() {
     @ViewChild('ChildComp') public variableChildComponent: ChildComp;
}

:

beforeEach(() => {
  TestBed.configureTestingModule({
     declarations: [ TestedComponent, ChildComp]
  })
  fixture = TestBed.createComponent(TestedComponent);
  comp = fixture.componentInstance;
  spyOn(TestedComponent.variableChildComponent, 'someMethod').and.returnValue(true);
});

+2

Source: https://habr.com/ru/post/1665369/


All Articles