Skip to content

Commit f46321b

Browse files
committed
test: add test case for matching on page.path when page also has matchPath
1 parent a64fedf commit f46321b

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

e2e-tests/adapters/cypress/e2e/client-only.cy.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,42 @@ describe("Paths", () => {
6565
name: "client-only/named-wildcard",
6666
param: "corinno/fenring",
6767
},
68+
{
69+
name: "client-only-created-with-gatsby-node",
70+
// matching on page.path
71+
param: "",
72+
},
73+
{
74+
name: "client-only-created-with-gatsby-node",
75+
// matching on page.matchPath
76+
param: "match-path",
77+
},
78+
{
79+
name: "client-only-param-created-with-gatsby-node",
80+
// matching on page.path
81+
param: "",
82+
},
83+
{
84+
name: "client-only-param-created-with-gatsby-node",
85+
// matching on page.matchPath
86+
param: "single-param",
87+
},
88+
{
89+
name: "client-only-wildcard-created-with-gatsby-node",
90+
// matching on page.path
91+
param: "",
92+
},
93+
{
94+
name: "client-only-wildcard-created-with-gatsby-node",
95+
// matching on page.matchPath
96+
param: "deeply/nested/path",
97+
},
6898
] as const
6999

70100
for (const route of routes) {
71-
it(`should return "${route.name}" result`, () => {
101+
it(`should return "${route.name}${
102+
route.param ? `/${route.param}` : ""
103+
}" result`, () => {
72104
cy.visit(
73105
`/routes/${route.name}${route.param ? `/${route.param}` : ""}`
74106
).waitForRouteChange()

e2e-tests/adapters/gatsby-node.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ export const createPages: GatsbyNode["createPages"] = async ({
5353
}
5454
`)
5555

56+
createPage({
57+
path: applyTrailingSlashOption(
58+
`/routes/client-only-param-created-with-gatsby-node`,
59+
TRAILING_SLASH
60+
),
61+
matchPath: `/routes/client-only-param-created-with-gatsby-node/:id`,
62+
component: path.resolve(`./src/templates/match-path-with-gatsby-node.jsx`),
63+
context: {
64+
title: `client-only-param-created-with-gatsby-node`,
65+
},
66+
})
67+
createPage({
68+
path: applyTrailingSlashOption(
69+
`/routes/client-only-wildcard-created-with-gatsby-node`,
70+
TRAILING_SLASH
71+
),
72+
matchPath: `/routes/client-only-wildcard-created-with-gatsby-node/*id`,
73+
component: path.resolve(`./src/templates/match-path-with-gatsby-node.jsx`),
74+
context: {
75+
title: `client-only-wildcard-created-with-gatsby-node`,
76+
},
77+
})
5678
createPage({
5779
path: applyTrailingSlashOption(
5880
`/routes/ssg/remote-file-data-from-context/`,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from "react"
2+
import Layout from "../components/layout"
3+
4+
const ClientOnlyParamsCreatedWithGatsbyNode = props => (
5+
<Layout>
6+
<h1 data-testid="title">{props.pageContext.title}</h1>
7+
<p data-testid="params">{props.params.id}</p>
8+
</Layout>
9+
)
10+
11+
export const Head = () => (
12+
<title>Client-Only Params created with gatsby-node</title>
13+
)
14+
15+
export default ClientOnlyParamsCreatedWithGatsbyNode

0 commit comments

Comments
 (0)