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

后端 未结 4 1420
一生所求
一生所求 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:16

    You are already calling httpMock.verify(), which should fail if there are unexpected requests, and log some information about those requests to the console. If your expectOne failed with a "found none", and verify did not fail, then your service must not actually have called http.put(). Add some logging or step through the test in a debugger to see what's actually happening.

    As other answers have pointed out, this could be due to timing issues. Your service call does not return an Observable or Promise so your spec can't tell when it finishes. This means you'll have to manipulate time with waitForAsync or fakeAsync.

提交回复
热议问题