Repository: remix-run/react-router
File: packages/router/__tests__/router-test.ts (TypeScript)

Code before:
              test: "value",
            },
          })
        );

        // @ts-expect-error
        let actionRequest = actionStub.mock.calls[0][0]?.request;
        expect(actionRequest.method).toBe("POST");
        expect(actionRequest.url).toBe("http://localhost/child");
        expect(actionRequest.headers.get("Content-Type")).toBe(
          "application/x-www-form-urlencoded;charset=UTF-8"
        );
        expect((await actionRequest.formData()).get("key")).toBe("value");

        // @ts-expect-error
        let rootLoaderRequest = rootLoaderStub.mock.calls[0][0]?.request;
        // @ts-expect-error
        let childLoaderRequest = childLoaderStub.mock.calls[0][0]?.request;
        expect(rootLoaderRequest.method).toBe("POST");
        expect(rootLoaderRequest.url).toBe("http://localhost/child");
        expect(rootLoaderRequest.headers.get("test")).toBe("value");
        expect(await rootLoaderRequest.text()).toBe("");
        expect(childLoaderRequest.method).toBe("POST");
        expect(childLoaderRequest.url).toBe("http://localhost/child");
        expect(childLoaderRequest.headers.get("test")).toBe("value");
        // Can't re-read body here since it's the same request as the root
      });

      it("should support a requestContext passed to loaders and actions", async () => {
        let requestContext = { sessionId: "12345" };
        let rootStub = jest.fn(() => "ROOT");
        let childStub = jest.fn(() => "CHILD");
        let actionStub = jest.fn(() => "CHILD ACTION");
        let arg = (s) => s.mock.calls[0][0];
        let { query } = createStaticHandler([
          {
            id: "root",
            path: "/",
            loader: rootStub,
            children: [
              {
                id: "child",
                path: "child",
                action: actionStub,
                loader: childStub,
              },
            ],
          },
        ]);

        await query(createRequest("/child"), { requestContext });

Review comment (suggestion):
Because `query` is a single document-level `POST` request the loaders reflect `POST` as well, but we don't proxy along the `body`

Code after:
              test: "value",
            },
          })
        );

        // @ts-expect-error
        let actionRequest = actionStub.mock.calls[0][0]?.request;
        expect(actionRequest.method).toBe("POST");
        expect(actionRequest.url).toBe("http://localhost/child");
        expect(actionRequest.headers.get("Content-Type")).toBe(
          "application/x-www-form-urlencoded;charset=UTF-8"
        );
        expect((await actionRequest.formData()).get("key")).toBe("value");

        // @ts-expect-error
        let rootLoaderRequest = rootLoaderStub.mock.calls[0][0]?.request;
        // @ts-expect-error
        let childLoaderRequest = childLoaderStub.mock.calls[0][0]?.request;
        expect(rootLoaderRequest.method).toBe("GET");
        expect(rootLoaderRequest.url).toBe("http://localhost/child");
        expect(rootLoaderRequest.headers.get("test")).toBe("value");
        expect(await rootLoaderRequest.text()).toBe("");
        expect(childLoaderRequest.method).toBe("GET");
        expect(childLoaderRequest.url).toBe("http://localhost/child");
        expect(childLoaderRequest.headers.get("test")).toBe("value");
        // Can't re-read body here since it's the same request as the root
      });

      it("should support a requestContext passed to loaders and actions", async () => {
        let requestContext = { sessionId: "12345" };
        let rootStub = jest.fn(() => "ROOT");
        let childStub = jest.fn(() => "CHILD");
        let actionStub = jest.fn(() => "CHILD ACTION");
        let arg = (s) => s.mock.calls[0][0];
        let { query } = createStaticHandler([
          {
            id: "root",
            path: "/",
            loader: rootStub,
            children: [
              {
                id: "child",
                path: "child",
                action: actionStub,
                loader: childStub,
              },
            ],
          },
        ]);

        await query(createRequest("/child"), { requestContext });