style(http): fix linting error in http/testing (#18002)
This commit is contained in:
parent
c723d42d0a
commit
09f1609f81
|
@ -35,14 +35,18 @@ export abstract class HttpTestingController {
|
|||
// Expect that exactly one request matches the given parameter.
|
||||
abstract expectOne(url: string, description?: string): TestRequest;
|
||||
abstract expectOne(params: RequestMatch, description?: string): TestRequest;
|
||||
abstract expectOne(matchFn: ((req: HttpRequest<any>) => boolean), description?: string): TestRequest;
|
||||
abstract expectOne(match: string|RequestMatch|((req: HttpRequest<any>) => boolean), description?: string): TestRequest;
|
||||
abstract expectOne(matchFn: ((req: HttpRequest<any>) => boolean), description?: string):
|
||||
TestRequest;
|
||||
abstract expectOne(
|
||||
match: string|RequestMatch|((req: HttpRequest<any>) => boolean),
|
||||
description?: string): TestRequest;
|
||||
|
||||
// Assert that no requests match the given parameter.
|
||||
abstract expectNone(url: string, description?: string): void;
|
||||
abstract expectNone(params: RequestMatch, description?: string): void;
|
||||
abstract expectNone(matchFn: ((req: HttpRequest<any>) => boolean), description?: string): void;
|
||||
abstract expectNone(match: string|RequestMatch|((req: HttpRequest<any>) => boolean), description?: string): void;
|
||||
abstract expectNone(
|
||||
match: string|RequestMatch|((req: HttpRequest<any>) => boolean), description?: string): void;
|
||||
|
||||
// Validate that all requests which were issued were flushed.
|
||||
abstract verify(opts?: {ignoreCancelled?: boolean}): void;
|
||||
|
|
|
@ -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') {
|
||||
|
|
Loading…
Reference in New Issue