Skip to content

Commit 5e1c200

Browse files
committed
typing
1 parent 64acca6 commit 5e1c200

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

apps/nextjs/app/[lang]/[pathPrefix]/[pathSuffix]/__tests__/page.test.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import React from 'react'
99
import { SessionProvider } from 'next-auth/react'
1010
import { WagmiProvider, createConfig, http, useAccount } from 'wagmi'
1111
import { celo } from 'viem/chains'
12+
import { useParams } from 'next/navigation'
1213

1314
import { useGuideData } from '@/lib/hooks/useGuideData'
1415

@@ -33,6 +34,15 @@ vi.mock('next-auth/react', async (importOriginal) => {
3334
}
3435
})
3536

37+
// Mock next/navigation to provide useParams
38+
vi.mock('next/navigation', async (importOriginal) => {
39+
const actual = await importOriginal<typeof import('next/navigation')>()
40+
return {
41+
...actual,
42+
useParams: vi.fn(),
43+
}
44+
})
45+
3646
// Mock useAccount to provide a consistent address
3747
vi.mock('wagmi', async (importOriginal) => {
3848
const actualWagmi = await importOriginal<typeof import('wagmi')>()
@@ -61,6 +71,7 @@ describe('Page', () => {
6171

6272
beforeEach(() => {
6373
vi.clearAllMocks()
74+
vi.mocked(useParams).mockReturnValue({ lang: 'en', pathPrefix: 'guia', pathSuffix: 'celo-ubi' })
6475
mockUnified.mockReturnValue({
6576
use: mockUse,
6677
parse: mockParse,
@@ -99,7 +110,7 @@ describe('Page', () => {
99110
render(
100111
<WagmiProvider config={config}>
101112
<SessionProvider session={mockSession as any}>
102-
<Page params={params} />
113+
<Page />
103114
</SessionProvider>
104115
</WagmiProvider>
105116
)

apps/nextjs/app/[lang]/[pathPrefix]/[pathSuffix]/page.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import axios, { AxiosError } from 'axios'
44
import { useSession, getCsrfToken } from 'next-auth/react'
55
import Link from 'next/link'
6+
import { useParams } from 'next/navigation'
67
import { useEffect, useState, useCallback } from 'react'
78
import remarkParse from 'remark-parse'
89
import remarkGfm from 'remark-gfm'
@@ -19,18 +20,11 @@ import { Button } from '@/components/ui/button'
1920
import { useGuideData } from '@/lib/hooks/useGuideData'
2021
import { remarkFillInTheBlank } from '@/lib/remarkFillInTheBlank.mjs'
2122

22-
type PageProps = {
23-
params: {
24-
lang: string
25-
pathPrefix: string
26-
pathSuffix: string
27-
}
28-
}
29-
30-
export default function Page({ params }: PageProps) {
23+
export default function Page() {
24+
const params = useParams()
3125
const { address } = useAccount()
3226
const { data: session } = useSession()
33-
const { lang, pathPrefix, pathSuffix } = params
27+
const { lang, pathPrefix, pathSuffix } = params as { lang: string; pathPrefix: string; pathSuffix: string }
3428
const [csrfToken, setCsrfToken] = useState('')
3529

3630
const {

0 commit comments

Comments
 (0)