MCPcopy
hub / github.com/angular/angular / MockFetchResponse

Class MockFetchResponse

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

Source from the content-addressed store, hash-verified

819}
820
821class MockFetchResponse {
822 public url?: string;
823 public headers: Record<string, string> = {};
824
825 public progress: number[] = [];
826
827 private sub$ = new Subject<any>();
828 public stream = new ReadableStream({
829 start: (controller) => {
830 this.sub$.subscribe({
831 next: (val) => {
832 controller.enqueue(new TextEncoder().encode(val));
833 },
834 complete: () => {
835 controller.close();
836 },
837 });
838 },
839 });
840
841 public setBody(body: any) {
842 this.sub$.next(body);
843 this.sub$.complete();
844 }
845
846 public setupBodyStream(body?: string) {
847 if (body && this.progress.length) {
848 this.headers['content-length'] = `${body.length}`;
849 let shift = 0;
850 this.progress.forEach((loaded) => {
851 this.sub$.next(body.substring(shift, loaded));
852 shift = loaded;
853 });
854 this.sub$.next(body.substring(shift, body.length));
855 } else {
856 this.sub$.next(body);
857 }
858
859 this.sub$.complete();
860 }
861}

Callers

nothing calls this directly

Calls 3

enqueueMethod · 0.80
subscribeMethod · 0.65
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…