|
| 1 | +/** |
| 2 | + * @jest-environment node |
| 3 | + */ |
| 4 | + |
1 | 5 | import * as React from "react";
|
2 | 6 | import * as ReactDOMServer from "react-dom/server";
|
3 | 7 | import type { StaticHandlerContext } from "@remix-run/router";
|
@@ -642,6 +646,44 @@ describe("A <StaticRouterProvider>", () => {
|
642 | 646 | `);
|
643 | 647 | });
|
644 | 648 |
|
| 649 | + it("renders absolute links correctly", async () => { |
| 650 | + let routes = [ |
| 651 | + { |
| 652 | + path: "/", |
| 653 | + element: ( |
| 654 | + <> |
| 655 | + <Link to="/the/path">relative path</Link> |
| 656 | + <Link to="http://localhost/the/path">absolute same-origin url</Link> |
| 657 | + <Link to="https://remix.run">absolute different-origin url</Link> |
| 658 | + <Link to="mailto:foo@baz.com">absolute mailto: url</Link> |
| 659 | + </> |
| 660 | + ), |
| 661 | + }, |
| 662 | + ]; |
| 663 | + let { query } = createStaticHandler(routes); |
| 664 | + |
| 665 | + let context = (await query( |
| 666 | + new Request("http://localhost/", { |
| 667 | + signal: new AbortController().signal, |
| 668 | + }) |
| 669 | + )) as StaticHandlerContext; |
| 670 | + |
| 671 | + let html = ReactDOMServer.renderToStaticMarkup( |
| 672 | + <React.StrictMode> |
| 673 | + <StaticRouterProvider |
| 674 | + router={createStaticRouter(routes, context)} |
| 675 | + context={context} |
| 676 | + /> |
| 677 | + </React.StrictMode> |
| 678 | + ); |
| 679 | + expect(html).toMatch( |
| 680 | + '<a href="/the/path">relative path</a>' + |
| 681 | + '<a href="http://localhost/the/path">absolute same-origin url</a>' + |
| 682 | + '<a href="https://remix.run">absolute different-origin url</a>' + |
| 683 | + '<a href="mailto:foo@baz.com">absolute mailto: url</a>' |
| 684 | + ); |
| 685 | + }); |
| 686 | + |
645 | 687 | describe("boundary tracking", () => {
|
646 | 688 | it("tracks the deepest boundary during render", async () => {
|
647 | 689 | let routes = [
|
|
0 commit comments