-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Closed
Labels
area: common/httpIssues related to HTTP and HTTP ClientIssues related to HTTP and HTTP ClientfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issuesfeature: in backlogFeature request for which voting has completed and is now in the backlogFeature request for which voting has completed and is now in the backlogfeature: under considerationFeature request for which voting has completed and the request is now under considerationFeature request for which voting has completed and the request is now under considerationstate: has PR
Milestone
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Related to #19903
When testing a request that contains query parameters, the test throws 2 errors:
- Expected one matching request for criteria "Match URL: ./assets/mock/modules.json", found none.
- Expected no open requests, found 1: GET ./assets/mock/modules.json
Appending the paramters to the expected URL does not work either.
Expected behavior
Test failure message should show the full path including parameters.
OR
We should be able to specify expected parameters or ignore all.
Minimal reproduction of the problem with instructions
[example.service.spec.ts]
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { Injector } from '@angular/core';
import { async, TestBed } from '@angular/core/testing';
import { ExampleService } from './example.service';
fdescribe('Create a test suite for the Example Service', () => {
let injector: Injector;
let exampleService: ExampleService;
let httpMock: HttpTestingController;
beforeEach(() => {
injector = TestBed.configureTestingModule({
imports:
[HttpClientTestingModule],
providers:
[ExampleService]
});
exampleService = injector.get(ExampleService);
httpMock = injector.get(HttpTestingController);
});
afterEach(() => {
httpMock.verify();
});
it('should not immediately connect to the server', () => {
httpMock.expectNone({});
});
describe('when fetching all stuff', () => {
it('should make a GET request', async(() => {
exampleService.getStuff();
let req = httpMock.expectOne(`./assets/mock/modules.json`);
expect(req.request.method).toEqual('GET');
req.flush([]);
}));
});
});
[example.service.ts]
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable()
export class ExampleService {
constructor(private http: HttpClient) {
}
getStuff() {
let params = new HttpParams().append('testparam', 'testvalue')
return this.http.get('./assets/mock/modules.json', {params}).toPromise().then(value => {
return value
})
}
}
What is the motivation / use case for changing the behavior?
Currently it is impossible to test http requests in a service which contain query parameters.
Environment
Angular version: 4.4.4
Browser:
- [X] Chrome (desktop) version 61.0.3163.100
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: V8.4.0
- Platform: Windows
Others:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: common/httpIssues related to HTTP and HTTP ClientIssues related to HTTP and HTTP ClientfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issuesfeature: in backlogFeature request for which voting has completed and is now in the backlogFeature request for which voting has completed and is now in the backlogfeature: under considerationFeature request for which voting has completed and the request is now under considerationFeature request for which voting has completed and the request is now under considerationstate: has PR
