I'm trying to write a simple unit test case for the below functions,
getMembers() {
this.service.getMembers()
.subscribe(response => {
this.allMembers = response;
})
}
Below is the specs which I've written,
it("should call getMembers subscribe method", fakeAsync(() => {
let membersSpy = spyOn(apiService, 'getMembers' ).and.returnValue(of(mockData));
let subSpy = spyOn(apiService.getMembers(),'subscribe');
homeComponent.getMembers();
fixture.detectChanges();
expect(membersSpy).toHaveBeenCalledBefore(subSpy);
expect(subSpy).toHaveBeenCalled();
}));
it("should call getMembers and return list of members", fakeAsync(() => {
expect(homeComponent.allMembers).toBeDefined();
expect(homeComponent.allMembers.length).toBeGreaterThan(1);
}));
I'm getting the below error for this specs should call getMembers and return list of members
Expected undefined to be defined.
What I'm doing wrong here ?