MCPcopy Create free account
hub / github.com/angular/angular / MockFetchResponse

Class MockFetchResponse

packages/common/http/test/fetch_spec.ts:913–953  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

911}
912
913class MockFetchResponse {
914 public url?: string;
915 public headers: Record<string, string> = {};
916
917 public progress: number[] = [];
918
919 private sub$ = new Subject<any>();
920 public stream = new ReadableStream({
921 start: (controller) => {
922 this.sub$.subscribe({
923 next: (val) => {
924 controller.enqueue(val instanceof Uint8Array ? val : new TextEncoder().encode(val));
925 },
926 complete: () => {
927 controller.close();
928 },
929 });
930 },
931 });
932
933 public setBody(body: any) {
934 this.sub$.next(body);
935 this.sub$.complete();
936 }
937
938 public setupBodyStream(body?: string) {
939 if (body && this.progress.length) {
940 this.headers['content-length'] = `${body.length}`;
941 let shift = 0;
942 this.progress.forEach((loaded) => {
943 this.sub$.next(body.substring(shift, loaded));
944 shift = loaded;
945 });
946 this.sub$.next(body.substring(shift, body.length));
947 } else {
948 this.sub$.next(body);
949 }
950
951 this.sub$.complete();
952 }
953}

Callers

nothing calls this directly

Calls 3

enqueueMethod · 0.80
subscribeMethod · 0.65
closeMethod · 0.45

Tested by

no test coverage detected