Sanika Bagjilewale
Sanika Bagjilewale

Reputation: 53

How to unit test nested functions in angular using jasmine-karna

I am trying to test SetRole function which is calling GetRole function in the end, but I am unable to cover the line in code coverage. Please guide me related to testing cascaded function, nested function, function in the function.

component.ts

SetRole(inp){
this.role = inp;
this.GetRole()
}

Upvotes: 3

Views: 2093

Answers (1)

Kartik Dolas
Kartik Dolas

Reputation: 761

Try this:

    it('SetRole',() => {
    
    const inp = 'dummyInput';
    const spy = spyOn(component,'GetRole')
    component.SetRole(inp)
    
    expect(spy).toHaveBeenCalled()
});

Upvotes: 2

Related Questions