Questions tagged [httptestingcontroller]

15 questions
6
votes
1 answer

How to test multiple requests in pipeline in Angular?

I want to test 3 requests done inside a pipeline. Simplified example: httpClient.get(testUrl) .pipe( mergeMap(() => range(0, 2)), mergeMap(() => httpClient.get(testUrl)), ) I'm using the official…
Adrian
  • 9,102
  • 4
  • 40
  • 35
3
votes
0 answers

Jasmine unit test request does not flush when testing http error as response

I am attempting to flush a response with an http 400 error using the HttpTestingController . However it does not appear to ever be flushed, as the delegate of the subscription is never called. Logging the _cancelled property of the request object…
3
votes
1 answer

Angular unit test - testing retryWhen in HttpInterceptor

I'm trying to test a retryWhen operator in an http interceptor but I'm getting an error when trying to repeat my service call multiple times: "Error: Expected one matching request for criteria "Match URL: http://someurl/tesdata", found none." So I…
BWG
  • 304
  • 3
  • 15
2
votes
0 answers

How do I unit test if http request has been canceled using HttpTestingClientModule?

My component is invoking the method to get data from the server, it happens in ngOnInit lifecycle of the component. The request takes some time, and the user can navigate away from current view and destroy the component. In such a case, the get data…
VRa3
  • 21
  • 3
2
votes
0 answers

How to mock Angular HttpClient response within test of observable stream?

I have an observable that ultimately triggers a call to Angular HttpClient. I need to mock the response from the HttpClient, but I'm at a loss how to do it within the context of the TestScheduler run method. Say I have the following…
tek
  • 343
  • 1
  • 4
  • 10
1
vote
0 answers

HttpTestingController expectOne not working when Bootstrap directive is used

When I imitate a click on an element generated by the Bootstrap directive I can not mock HTTP requests in a unit test. Here I have a component with links for pagination. @Component({ template: `
1
vote
2 answers

How can I test http request params in Angular?

I am trying to test that http params are correct when I make a http request. When I do expect(req.request.params.get('action')).toEqual('pause'); the test fails: Expected: "pause" Received: null Service constructor(private _http:…
adrisons
  • 3,443
  • 3
  • 32
  • 48
0
votes
0 answers

HttpTestingController finds two requests instead of one in Angular test with jest

I am writing a unit test with jest for a service method that makes an http request to a local server that runs on json-server in localhost:3000 This is the service method: fetchData() { return…
Misko Jones
  • 87
  • 1
  • 8
0
votes
1 answer

Second observable is not returned by switchMap when using Angular TestBed

I'm trying to unit test a small part of the Modal component, but I'm having hard times working with observables. My main problems are http requests that are not invoked one after another when I run code in Karma and Jasmine (I guess Angular TestBed…
VRa3
  • 21
  • 3
0
votes
1 answer

spy on method when unit testing http interceptor in angular

I'm trying to unit test an http interceptor. The interceptor is used for authorization. I can test the basic success case, but I'm trying now to test the case where the API call fails because access token is out of date. My question is, how do I…
Mr Smith
  • 3,318
  • 9
  • 47
  • 85
0
votes
1 answer

Go Fiber not able to parse body in unit test

I am officially crying uncle to the benevolent samaritans of Stack Overflow. I am trying to unit test my GORM (Postgres) + Fiber API using a mock DB. I have a Card model and a CreateCardReqBody model for the POST request body. To setup the test, I…
0
votes
1 answer

How to test a method with multi-http calls

How do you test the findArtists method with the httpTestingController? So ideally what this service is doing is fetching some artists' data on the first get call but the data returned doesn't have all the data required for displaying in the…
Flash
  • 1,105
  • 14
  • 16
0
votes
1 answer

Angular HttpTestingController Unable to match url with params

I am new to HttpTesting controller. my expectations not working as the url contains HttpParams. here is my service, and spec.ts hasAccessControlException() { const apiPath =…
Mukil Deepthi
  • 6,072
  • 13
  • 71
  • 156
0
votes
1 answer

Angular 8 Jasmine not matching HTTP request

I have an Angular service making some HTTP requests, and I want to test that it's making them the right way. Among its dependencies, it also has an EnvironmentService that returns the correct API endpoints according to the environment, that I have…
Raibaz
  • 9,280
  • 10
  • 44
  • 65
0
votes
1 answer

Test case for a service method which contains a HTTP subscribe - Angular HTTP RxJs

I'm having a service method and it has a service call (HTTP call) and it subscribes immediately and based on the response code it executes the rest of the action command. Example: Service Method processData(id): void { const url =…