|
| 1 | +import { createStaticHandler } from "@remix-run/router"; |
| 2 | +import { act, fireEvent, render } from "@testing-library/react"; |
1 | 3 | import * as React from "react";
|
2 |
| -import { createMemoryRouter, RouterProvider } from "react-router-dom"; |
3 |
| -import { fireEvent, render, act } from "@testing-library/react"; |
| 4 | +import { createMemoryRouter, Outlet, RouterProvider } from "react-router-dom"; |
4 | 5 |
|
| 6 | +import { RemixBrowser } from "../browser"; |
5 | 7 | import type { LiveReload as ActualLiveReload } from "../components";
|
6 | 8 | import { Link, NavLink, RemixContext } from "../components";
|
7 |
| - |
| 9 | +import invariant from "../invariant"; |
| 10 | +import { RemixServer } from "../server"; |
8 | 11 | import "@testing-library/jest-dom/extend-expect";
|
9 | 12 |
|
10 | 13 | // TODO: Every time we touch LiveReload (without changing the API) these tests
|
@@ -199,3 +202,126 @@ describe("<Link />", () => {
|
199 | 202 | describe("<NavLink />", () => {
|
200 | 203 | itPrefetchesPageLinks(NavLink);
|
201 | 204 | });
|
| 205 | + |
| 206 | +describe("<RemixServer>", () => { |
| 207 | + it("handles empty default export objects from the compiler", async () => { |
| 208 | + let staticHandlerContext = await createStaticHandler([{ path: "/" }]).query( |
| 209 | + new Request("http://localhost/") |
| 210 | + ); |
| 211 | + invariant( |
| 212 | + !(staticHandlerContext instanceof Response), |
| 213 | + "Expected a context" |
| 214 | + ); |
| 215 | + |
| 216 | + let context = { |
| 217 | + manifest: { |
| 218 | + routes: { |
| 219 | + root: { |
| 220 | + hasLoader: false, |
| 221 | + hasAction: false, |
| 222 | + hasErrorBoundary: false, |
| 223 | + id: "root", |
| 224 | + module: "root.js", |
| 225 | + path: "/", |
| 226 | + }, |
| 227 | + empty: { |
| 228 | + hasLoader: false, |
| 229 | + hasAction: false, |
| 230 | + hasErrorBoundary: false, |
| 231 | + id: "empty", |
| 232 | + module: "empty.js", |
| 233 | + index: true, |
| 234 | + parentId: "root", |
| 235 | + }, |
| 236 | + }, |
| 237 | + entry: { imports: [], module: "" }, |
| 238 | + url: "", |
| 239 | + version: "", |
| 240 | + }, |
| 241 | + routeModules: { |
| 242 | + root: { |
| 243 | + default: () => { |
| 244 | + return ( |
| 245 | + <> |
| 246 | + <h1>Root</h1> |
| 247 | + <Outlet /> |
| 248 | + </> |
| 249 | + ); |
| 250 | + }, |
| 251 | + }, |
| 252 | + empty: { default: {} }, |
| 253 | + }, |
| 254 | + staticHandlerContext, |
| 255 | + future: {}, |
| 256 | + }; |
| 257 | + |
| 258 | + jest.spyOn(console, "warn").mockImplementation(() => {}); |
| 259 | + jest.spyOn(console, "error"); |
| 260 | + |
| 261 | + let { container } = render( |
| 262 | + <RemixServer context={context} url="http://localhost/" /> |
| 263 | + ); |
| 264 | + |
| 265 | + expect(console.warn).toHaveBeenCalledWith( |
| 266 | + 'Matched leaf route at location "/" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.' |
| 267 | + ); |
| 268 | + expect(console.error).not.toHaveBeenCalled(); |
| 269 | + expect(container.innerHTML).toMatch("<h1>Root</h1>"); |
| 270 | + }); |
| 271 | +}); |
| 272 | + |
| 273 | +describe("<RemixBrowser>", () => { |
| 274 | + it("handles empty default export objects from the compiler", () => { |
| 275 | + window.__remixContext = { |
| 276 | + url: "/", |
| 277 | + state: { |
| 278 | + loaderData: {}, |
| 279 | + }, |
| 280 | + future: {}, |
| 281 | + }; |
| 282 | + window.__remixRouteModules = { |
| 283 | + root: { |
| 284 | + default: () => { |
| 285 | + return ( |
| 286 | + <> |
| 287 | + <h1>Root</h1> |
| 288 | + <Outlet /> |
| 289 | + </> |
| 290 | + ); |
| 291 | + }, |
| 292 | + }, |
| 293 | + empty: { default: {} }, |
| 294 | + }; |
| 295 | + window.__remixManifest = { |
| 296 | + routes: { |
| 297 | + root: { |
| 298 | + hasLoader: false, |
| 299 | + hasAction: false, |
| 300 | + hasErrorBoundary: false, |
| 301 | + id: "root", |
| 302 | + module: "root.js", |
| 303 | + path: "/", |
| 304 | + }, |
| 305 | + empty: { |
| 306 | + hasLoader: false, |
| 307 | + hasAction: false, |
| 308 | + hasErrorBoundary: false, |
| 309 | + id: "empty", |
| 310 | + module: "empty.js", |
| 311 | + index: true, |
| 312 | + parentId: "root", |
| 313 | + }, |
| 314 | + }, |
| 315 | + entry: { imports: [], module: "" }, |
| 316 | + url: "", |
| 317 | + version: "", |
| 318 | + }; |
| 319 | + |
| 320 | + jest.spyOn(console, "error"); |
| 321 | + |
| 322 | + let { container } = render(<RemixBrowser />); |
| 323 | + |
| 324 | + expect(console.error).not.toHaveBeenCalled(); |
| 325 | + expect(container.innerHTML).toMatch("<h1>Root</h1>"); |
| 326 | + }); |
| 327 | +}); |
0 commit comments