style(http): fix linting error in http/testing (#18002)

This commit is contained in:
Jason Aden
2017-07-07 17:02:07 -07:00
committed by GitHub
parent c723d42d0a
commit 09f1609f81
2 changed files with 22 additions and 12 deletions

View File

@ -83,11 +83,13 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
* Requests returned through this API will no longer be in the list of open requests,
* and thus will not match twice.
*/
expectOne(match: string|RequestMatch|((req: HttpRequest<any>) => boolean), description?: string): TestRequest {
expectOne(match: string|RequestMatch|((req: HttpRequest<any>) => boolean), description?: string):
TestRequest {
description = description || this.descriptionFromMatcher(match);
const matches = this.match(match);
if (matches.length > 1) {
throw new Error(`Expected one matching request for criteria "${description}", found ${matches.length} requests.`);
throw new Error(
`Expected one matching request for criteria "${description}", found ${matches.length} requests.`);
}
if (matches.length === 0) {
throw new Error(`Expected one matching request for criteria "${description}", found none.`);
@ -99,11 +101,13 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
* Expect that no outstanding requests match the given matcher, and throw an error
* if any do.
*/
expectNone(match: string|RequestMatch|((req: HttpRequest<any>) => boolean), description?: string): void {
expectNone(match: string|RequestMatch|((req: HttpRequest<any>) => boolean), description?: string):
void {
description = description || this.descriptionFromMatcher(match);
const matches = this.match(match);
if (matches.length > 0) {
throw new Error(`Expected zero matching requests for criteria "${description}", found ${matches.length}.`);
throw new Error(
`Expected zero matching requests for criteria "${description}", found ${matches.length}.`);
}
}
@ -120,15 +124,17 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
if (open.length > 0) {
// Show the methods and URLs of open requests in the error, for convenience.
const requests = open.map(testReq => {
const url = testReq.request.urlWithParams.split('?')[0];
const method = testReq.request.method;
return `${method} ${url}`
}).join(', ');
const url = testReq.request.urlWithParams.split('?')[0];
const method = testReq.request.method;
return `${method} ${url}`
})
.join(', ');
throw new Error(`Expected no open requests, found ${open.length}: ${requests}`);
}
}
private descriptionFromMatcher(matcher: string|RequestMatch|((req: HttpRequest<any>) => boolean)): string {
private descriptionFromMatcher(matcher: string|RequestMatch|
((req: HttpRequest<any>) => boolean)): string {
if (typeof matcher === 'string') {
return `Match URL: ${matcher}`;
} else if (typeof matcher === 'object') {