Skip to content

Commit

Permalink
createRemixStub -> createRoutesStub
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanflorence committed Jun 20, 2024
1 parent bf6d9cf commit 7ad753e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-carrots-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router": major
---

rename createRemixStub to createRoutesStub
4 changes: 2 additions & 2 deletions packages/react-router-dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export type {
MetaDescriptor,
MetaFunction,
ServerRouterProps,
RemixStubProps,
RoutesTestStubProps,
} from "react-router";

export {
Expand Down Expand Up @@ -191,7 +191,7 @@ export {
Scripts,
PrefetchPageLinks,
ServerRouter,
createRemixStub,
createRoutesStub,
} from "react-router";

///////////////////////////////////////////////////////////////////////////////
Expand Down
42 changes: 21 additions & 21 deletions packages/react-router/__tests__/dom/ssr/meta-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { prettyDOM, render, screen } from "@testing-library/react";
import user from "@testing-library/user-event";
import * as React from "react";

import { Meta, Outlet, createRemixStub } from "../../../index";
import { Meta, Outlet, createRoutesStub } from "../../../index";

const getHtml = (c: HTMLElement) =>
prettyDOM(c, undefined, { highlight: false });

describe("meta", () => {
it("no meta export renders meta from nearest route meta in the tree", () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
id: "root",
path: "/",
Expand Down Expand Up @@ -37,7 +37,7 @@ describe("meta", () => {
]);

let { container } = render(
<RemixStub
<RoutesStub
hydrationData={{
loaderData: {
root: {
Expand Down Expand Up @@ -66,7 +66,7 @@ describe("meta", () => {
});

it("empty meta array does not render a tag", () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
meta: () => [],
Expand All @@ -81,7 +81,7 @@ describe("meta", () => {
},
]);

let { container } = render(<RemixStub />);
let { container } = render(<RoutesStub />);

expect(getHtml(container)).toMatchInlineSnapshot(`
"<div>
Expand All @@ -93,7 +93,7 @@ describe("meta", () => {
});

it("meta from `matches` renders meta tags", () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
id: "root",
path: "/",
Expand Down Expand Up @@ -123,7 +123,7 @@ describe("meta", () => {
},
]);

let { container } = render(<RemixStub />);
let { container } = render(<RoutesStub />);

expect(getHtml(container)).toMatchInlineSnapshot(`
"<div>
Expand All @@ -141,15 +141,15 @@ describe("meta", () => {
});

it("{ charSet } adds a <meta charset='utf-8' />", () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
meta: () => [{ charSet: "utf-8" }],
Component: Meta,
},
]);

let { container } = render(<RemixStub />);
let { container } = render(<RoutesStub />);

expect(getHtml(container)).toMatchInlineSnapshot(`
"<div>
Expand All @@ -161,15 +161,15 @@ describe("meta", () => {
});

it("{ title } adds a <title />", () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
meta: () => [{ title: "Document Title" }],
Component: Meta,
},
]);

let { container } = render(<RemixStub />);
let { container } = render(<RoutesStub />);

expect(getHtml(container)).toMatchInlineSnapshot(`
"<div>
Expand All @@ -181,7 +181,7 @@ describe("meta", () => {
});

it("{ property: 'og:*', content: '*' } adds a <meta property='og:*' />", () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
meta: () => [
Expand All @@ -192,7 +192,7 @@ describe("meta", () => {
},
]);

let { container } = render(<RemixStub />);
let { container } = render(<RoutesStub />);
expect(getHtml(container)).toMatchInlineSnapshot(`
"<div>
<meta
Expand Down Expand Up @@ -221,7 +221,7 @@ describe("meta", () => {
email: ["[email protected]", "[email protected]"],
};

let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
meta: () => [
Expand All @@ -233,7 +233,7 @@ describe("meta", () => {
},
]);

let { container } = render(<RemixStub />);
let { container } = render(<RoutesStub />);

// For some reason, prettyDOM strips the script tag (maybe because of
// dangerouslySetInnerHTML), so we just parse the HTML out into JSON and assert that way
Expand All @@ -244,7 +244,7 @@ describe("meta", () => {
});

it("{ tagName: 'link' } adds a <link />", () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
meta: () => [
Expand All @@ -258,7 +258,7 @@ describe("meta", () => {
},
]);

let { container } = render(<RemixStub />);
let { container } = render(<RoutesStub />);
expect(getHtml(container)).toMatchInlineSnapshot(`
"<div>
<link
Expand All @@ -270,7 +270,7 @@ describe("meta", () => {
});

it("does not mutate meta when using tagName", async () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
meta: ({ data }) => data?.meta,
Expand All @@ -297,7 +297,7 @@ describe("meta", () => {
},
]);

let { container } = render(<RemixStub />);
let { container } = render(<RoutesStub />);

await screen.findByText("Increment 0");
expect(getHtml(container)).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -329,7 +329,7 @@ describe("meta", () => {
});

it("loader errors are passed to meta", () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
Component() {
Expand Down Expand Up @@ -361,7 +361,7 @@ describe("meta", () => {
]);

let { container } = render(
<RemixStub hydrationData={{ errors: { index: new Error("Oh no!") } }} />
<RoutesStub hydrationData={{ errors: { index: new Error("Oh no!") } }} />
);
expect(getHtml(container)).toMatchInlineSnapshot(`
"<div>
Expand Down
32 changes: 16 additions & 16 deletions packages/react-router/__tests__/dom/stub-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ import {
useLoaderData,
useMatches,
json,
createRemixStub,
createRoutesStub,
} from "../../index";

test("renders a route", () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
Component: () => <div>HOME</div>,
},
]);

render(<RemixStub />);
render(<RoutesStub />);

expect(screen.getByText("HOME")).toBeInTheDocument();
});

test("renders a nested route", () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
Component() {
return (
Expand All @@ -45,15 +45,15 @@ test("renders a nested route", () => {
},
]);

render(<RemixStub />);
render(<RoutesStub />);

expect(screen.getByText("ROOT")).toBeInTheDocument();
expect(screen.getByText("INDEX")).toBeInTheDocument();
});

// eslint-disable-next-line jest/expect-expect
test("loaders work", async () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
Component() {
Expand All @@ -66,14 +66,14 @@ test("loaders work", async () => {
},
]);

render(<RemixStub />);
render(<RoutesStub />);

await waitFor(() => screen.findByText("Message: hello"));
});

// eslint-disable-next-line jest/expect-expect
test("actions work", async () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
Component() {
Expand All @@ -91,7 +91,7 @@ test("actions work", async () => {
},
]);

render(<RemixStub />);
render(<RoutesStub />);

user.click(screen.getByText("Submit"));
await waitFor(() => screen.findByText("Message: hello"));
Expand All @@ -100,7 +100,7 @@ test("actions work", async () => {
// eslint-disable-next-line jest/expect-expect
test("fetchers work", async () => {
let count = 0;
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
path: "/",
Component() {
Expand All @@ -120,7 +120,7 @@ test("fetchers work", async () => {
},
]);

render(<RemixStub />);
render(<RoutesStub />);

user.click(screen.getByText("idle 0"));
await waitFor(() => screen.findByText("idle 1"));
Expand All @@ -135,7 +135,7 @@ test("can pass a predefined loader", () => {
return json({ hi: "there" });
}

createRemixStub([
createRoutesStub([
{
path: "/example",
loader,
Expand All @@ -144,7 +144,7 @@ test("can pass a predefined loader", () => {
});

test("can pass context values", async () => {
let RemixStub = createRemixStub(
let RoutesStub = createRoutesStub(
[
{
path: "/",
Expand Down Expand Up @@ -177,7 +177,7 @@ test("can pass context values", async () => {
{ context: "hello" }
);

render(<RemixStub initialEntries={["/hello"]} />);
render(<RoutesStub initialEntries={["/hello"]} />);

expect(await screen.findByTestId("root")).toHaveTextContent(
/context: hello/i
Expand All @@ -188,7 +188,7 @@ test("can pass context values", async () => {
});

test("all routes have ids", () => {
let RemixStub = createRemixStub([
let RoutesStub = createRoutesStub([
{
Component() {
return (
Expand Down Expand Up @@ -218,7 +218,7 @@ test("all routes have ids", () => {
},
]);

render(<RemixStub />);
render(<RoutesStub />);

let matchesTextContent = screen.getByTestId("matches").textContent;

Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ export type {
} from "./lib/dom/ssr/routeModules";
export type { ServerRouterProps } from "./lib/dom/ssr/server";
export { ServerRouter } from "./lib/dom/ssr/server";
export type { RemixStubProps } from "./lib/dom/ssr/create-remix-stub";
export { createRemixStub } from "./lib/dom/ssr/create-remix-stub";
export type { RoutesTestStubProps } from "./lib/dom/ssr/routes-test-stub";
export { createRoutesStub } from "./lib/dom/ssr/routes-test-stub";
export { defineRoute } from "./lib/router/define-route";

///////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface AppLoadContext {
[key: string]: unknown;
}

export interface RemixStubProps {
export interface RoutesTestStubProps {
/**
* The initial entries in the history stack. This allows you to start a test with
* multiple locations already in the history stack (for testing a back navigation, etc.)
Expand Down Expand Up @@ -86,16 +86,16 @@ export interface RemixStubProps {
/**
* @category Utils
*/
export function createRemixStub(
export function createRoutesStub(
routes: StubRouteObject[],
context: AppLoadContext = {}
) {
return function RemixStub({
return function RoutesTestStub({
initialEntries,
initialIndex,
hydrationData,
future,
}: RemixStubProps) {
}: RoutesTestStubProps) {
let routerRef = React.useRef<ReturnType<typeof createMemoryRouter>>();
let remixContextRef = React.useRef<RemixContextObject>();

Expand Down

0 comments on commit 7ad753e

Please sign in to comment.