Next.js + TypeScriptでuseRouter()をモックする
更新日:
投稿日:
投稿日:
確認環境
| Env | Ver |
|---|---|
| next | 11.1.2 |
| typescript | 4.3.4 |
サンプルコード
__mocks__/next/router.ts
export const useRouter = () => {
return {
route: '/',
pathname: '',
query: '',
asPath: '',
push: jest.fn(),
replace: jest.fn(),
events: {
on: jest.fn(),
off: jest.fn(),
},
beforePopState: jest.fn(() => null),
prefetch: jest.fn(() => null),
};
};