TypeError: Can not read property of undefined(reading 'then') Angular unit test case

Viewed 53

Here is my method in ts file and test case, When I am trying to run my test case, I am getting undefined error reading then.

onCancel(){
    this.router.navigate(['hello']).then(() =>{
    window.router.reload();
    });
    }

test-case spec.ts -

    it("should navigate to hello", function () 
    {
    component.onCancel();
    expect(routerSpy.navigate).toHaveBeenCalled();
    });
0 Answers
Related