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

Class MockFetchResponse

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

enqueueMethod · 0.80
subscribeMethod · 0.65
closeMethod · 0.45

Tested by

no test coverage detected