how to write SpyOn()

  Kiến thức lập trình
let compoent = MockComponent;

it('should be called the your Component', () =>{

component.yourComponent() // first called your component

spyOn(component, 'method').and.returnValue('expeted data')

})

spyon is observe the component

New contributor

Mahesh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

First create the spy, then execute the method, then finally evaluate it!

let component = MockComponent;

it('should be called the your Component', () =>{
    spyOn(component, 'method').and.returnValue('expeted data')
    component.yourComponent() // first called your component
    expect(component.method).toHaveBeenCalled();
})

LEAVE A COMMENT