Skip to content

Commit

Permalink
feat(test/e2e): Add router link click case in 'middleware-base-path'
Browse files Browse the repository at this point in the history
  • Loading branch information
flex-kyunghwa committed Sep 15, 2022
1 parent 9780d81 commit 7477fcd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
@@ -0,0 +1,11 @@
import { useRouter } from 'next/router'

export default function DynamicRoutes() {
const { query } = useRouter()

return (
<main>
<h1 id="route-name">{query.routeName}</h1>
</main>
)
}
5 changes: 5 additions & 0 deletions test/e2e/middleware-base-path/app/pages/index.js
Expand Up @@ -27,6 +27,11 @@ export default function Main({ message }) {
<a>redirect me to about</a>
</Link>
</li>
<li>
<Link href="dynamic-routes/hello-world">
<a id="go-to-hello-world-anchor">Hello World</a>
</Link>
</li>
</ul>
</div>
)
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/middleware-base-path/test/index.test.ts
Expand Up @@ -35,4 +35,14 @@ describe('Middleware base tests', () => {
const $ = cheerio.load(html)
expect($('.title').text()).toBe('About Page')
})
it('router.query must exist when Link clicked page routing', async () => {
const browser = await webdriver(next.url, '/root')
try {
await browser.elementById('go-to-hello-world-anchor').click()
const routeName = await browser.elementById('route-name').text()
expect(routeName).toMatch('hello-world')
} finally {
await browser.close()
}
})
})

0 comments on commit 7477fcd

Please sign in to comment.