Hello, I am testing my app with Jasmine and Karma, but I am having some problems with my service. The code below is my service;
export class CustomerService extends SMService{ ... getCustomers(sort: string, order: string, page: number, filter: CustomerFilter): Observable<SMServiceListResponse<Customer>> { return super.getObjects(sort, order, page, filter); } ... } I want to test if method 'getObjects' is called when getCustomers is executed. Below is the it() : let mocker: Mocker; let mockCustomer: any; beforeEach(() => { mocker = new Mocker(); mockCustomer = {data: mocker.getCustomers(2), pagination: {}}; }); afterEach(() => { httpTestingController.verify(); }); it('should return expected customers by calling once', () => { spyOn(customerService, 'getObjects').and.callThrough(); customerService.getCustomers('', '', 0, null).subscribe( response => { expect(response).toEqual(mockCustomer, 'should return expected customers'); expect(response.data.length).toEqual(mockCustomer.data.length); } ); // Error: This is never called expect(customerService.getObjects).toHaveBeenCalledTimes(1); const req = httpTestingController.expectOne(customerEndpoint); expect(req.request.method).toEqual('GET'); req.flush(mockCustomer); // Return expected Customers }); Everything is ok but .getObjects is never called. I have tried a lot of ways to solve this but cant do it. -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/angular/49045f87-7828-4241-9032-34aa02d3457e%40googlegroups.com.