Angular 5 Jasmine Error: Expected one matching request for criteria found none

后端 未结 4 1421
一生所求
一生所求 2021-01-04 05:34

I have a very simple service call and a jasmine test for it.

Service call:

myServiceCall(testId: number) : void {
    const url = `${this.url}/param         


        
4条回答
  •  悲哀的现实
    2021-01-04 06:22

    You should have your test inside a fakeAsync and call tick() at the end of your test. like

    it('should call myServiceCall', inject([MyService], fakeAsync((service: MyService) => {
        let testId = undefined;
        service.myServiceCall(testId);
        let req = httpMock.expectOne(environment.baseUrl + "/paramX/123");
    
        expect(req.request.url).toBe(environment.baseUrl + "/paramX/123");
        expect(req.request.body).toEqual({});
    
        req.flush({});
        httpMock.verify();
        tick();
    
    })));
    

提交回复
热议问题