From 09f1609f819f54256bdba69f6e3bf29d5ad40249 Mon Sep 17 00:00:00 2001 From: Jason Aden Date: Fri, 7 Jul 2017 17:02:07 -0700 Subject: [PATCH] style(http): fix linting error in http/testing (#18002) --- packages/common/http/testing/src/api.ts | 10 ++++++--- packages/common/http/testing/src/backend.ts | 24 +++++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/packages/common/http/testing/src/api.ts b/packages/common/http/testing/src/api.ts index 47c82053b6..81af8b224c 100644 --- a/packages/common/http/testing/src/api.ts +++ b/packages/common/http/testing/src/api.ts @@ -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) => boolean), description?: string): TestRequest; - abstract expectOne(match: string|RequestMatch|((req: HttpRequest) => boolean), description?: string): TestRequest; + abstract expectOne(matchFn: ((req: HttpRequest) => boolean), description?: string): + TestRequest; + abstract expectOne( + match: string|RequestMatch|((req: HttpRequest) => 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) => boolean), description?: string): void; - abstract expectNone(match: string|RequestMatch|((req: HttpRequest) => boolean), description?: string): void; + abstract expectNone( + match: string|RequestMatch|((req: HttpRequest) => boolean), description?: string): void; // Validate that all requests which were issued were flushed. abstract verify(opts?: {ignoreCancelled?: boolean}): void; diff --git a/packages/common/http/testing/src/backend.ts b/packages/common/http/testing/src/backend.ts index 43bc0f0d36..66cf5344e0 100644 --- a/packages/common/http/testing/src/backend.ts +++ b/packages/common/http/testing/src/backend.ts @@ -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) => boolean), description?: string): TestRequest { + expectOne(match: string|RequestMatch|((req: HttpRequest) => 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) => boolean), description?: string): void { + expectNone(match: string|RequestMatch|((req: HttpRequest) => 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) => boolean)): string { + private descriptionFromMatcher(matcher: string|RequestMatch| + ((req: HttpRequest) => boolean)): string { if (typeof matcher === 'string') { return `Match URL: ${matcher}`; } else if (typeof matcher === 'object') {