Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 11x 11x 10x | import type { HttpRequest } from '@angular/common/http'; import type { HttpTestingController, RequestMatch, TestRequest } from '@angular/common/http/testing'; export type THttpRequestMatcher<T> = string | RequestMatch | ((req: HttpRequest<T>) => boolean); /** * This function should be used in unit tests to flush HttpTestingController requests. */ export function flushHttpRequests<T>( httpController: HttpTestingController, verify = false, matcher: THttpRequestMatcher<T> = (req: HttpRequest<T>): boolean => true, responseData: | string | number | Record<string, unknown> | ArrayBuffer | Blob | Array<string | number | Record<string, unknown> | null> | null = {}, produceError?: boolean, ): void { httpController.match(matcher).forEach((req: TestRequest) => { return produceError === true ? req.error(new ProgressEvent('error', { total: 1, loaded: 1, cancelable: true })) : !req.cancelled ? req.flush(responseData) : null; }); if (verify) { httpController.verify(); } } |