Checking local variable while unit testing on a component in Angular gives error

后端 未结 1 1133
你的背包
你的背包 2021-01-16 23:53

Suppose there are 2 components : AppComponent and TestComponent. I am calling TestComponent using it\'s directive in the HTML template of AppComponent. Now TestComponent has

相关标签:
1条回答
  • 2021-01-17 00:47

    As you have added spy on onClick function, it will never fire and update value of filter.

    You need to remove that spy function and see the actual value change.

    Change test as below:

    it('should check whether onClick is called on button click or not and also the value of filter', () => {
          component.myTitle = temp;
          fixture.detectChanges();
    
          let btn = fixture.debugElement.query(By.css('button'));
          btn.triggerEventHandler('click', null);
    
          fixture.whenStable().then(() => {
            expect(component.filter).toEqual("GokuSSj3");
          });

    0 讨论(0)
提交回复
热议问题