/ packages / react-hooks / happyDomSetup.ts
happyDomSetup.ts
 1  import { GlobalRegistrator } from "@happy-dom/global-registrator";
 2  
 3  export const register = () => {
 4    // Store deno's web APIs and reassign them after happydom is registered
 5    const denoAbortController = globalThis.AbortController;
 6    const denoBlob = globalThis.Blob;
 7    const denoFetch = globalThis.fetch;
 8    const denoFile = globalThis.File;
 9    const denoFileReader = globalThis.FileReader;
10    const denoFormData = globalThis.FormData;
11    const denoHeaders = globalThis.Headers;
12    const denoRequest = globalThis.Request;
13    const denoResponse = globalThis.Response;
14    const denoWritableStream = globalThis.WritableStream;
15    const denoReadableStream = globalThis.ReadableStream;
16  
17    GlobalRegistrator.register();
18  
19    globalThis.AbortController = denoAbortController;
20    globalThis.Blob = denoBlob;
21    globalThis.fetch = denoFetch;
22    globalThis.File = denoFile;
23    globalThis.FileReader = denoFileReader;
24    globalThis.FormData = denoFormData;
25    globalThis.Headers = denoHeaders;
26    globalThis.Request = denoRequest;
27    globalThis.Response = denoResponse;
28    globalThis.WritableStream = denoWritableStream;
29    globalThis.ReadableStream = denoReadableStream;
30  };
31  
32  export const unregister = () => {
33    return GlobalRegistrator.unregister();
34  };