{"_id":"@cubbk/next-router-mock","_rev":"5-fee354cc9a237a06fe8c716abdbfca8b","name":"@cubbk/next-router-mock","dist-tags":{"latest":"0.11.0"},"versions":{"0.9.13":{"name":"@cubbk/next-router-mock","version":"0.9.13","keywords":["react","next","next.js","nextjs","router","mock","test","testing"],"author":"","license":"MIT","_id":"@cubbk/next-router-mock@0.9.13","maintainers":[{"name":"cubbic","email":"danpopa1998@gmail.com"}],"homepage":"https://github.com/cubbk/next-router-mock#readme","bugs":{"url":"https://github.com/cubbk/next-router-mock/issues"},"dist":{"shasum":"cf7d729bc7b53ea3e3d3b209b1a64c06c0230a49","tarball":"https://registry.npmjs.org/@cubbk/next-router-mock/-/next-router-mock-0.9.13.tgz","fileCount":108,"integrity":"sha512-WdDGumCaQKP9op6f3+rtpkvtJQvidvtCn1YkoYj2o8FtSSX7zOWAIedzgPnEUg3jOzKrzF5X5sxtHCgSnbWQdA==","signatures":[{"sig":"MEQCICqS5mB1WXU5hMfFPzFWq42awJrnSCmQ2YwQ0H1lReIgAiAWSR+qV/1G/+71G2Pnt9KHSls5oVZAi9RDXV7mBEy8sA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":145320},"main":"dist/index","types":"./dist/index.d.ts","gitHead":"7b2c260e1aad60db4aea3efe7bdb0ee5bfc162d2","scripts":{"docs":"doctoc README.md","lint":"prettier --list-different src","test":"jest","build":"npm run clean && tsc --project tsconfig.build.json","clean":"rimraf dist","checks":"npm run docs && npm run lint && npm run test && npm run build && npm run typecheck && npm run test:integration","release":"changeset publish","lint:fix":"prettier --write src","typecheck":"tsc --noEmit","prerelease":"npm run build","preversion":"npm run checks","test:watch":"jest --watch","build:watch":"npm run build -- --watch","test:exports":"cd test/test-exports && npm test","test:next-10":"cd test/next-10 && npm test","test:next-11":"cd test/next-11 && npm test","test:next-12":"cd test/next-12 && npm test","test:next-13":"cd test/next-13 && npm test","prepublishOnly":"npm run build","test:next-12.2":"cd test/next-12.2+ && npm test","test:next-13.5":"cd test/next-13.5 && npm test","test:example-app":"cd test/example-app && npm test","test:integration":"npm run build && npm run test:exports && npm run test:example-app && npm run test:next-10 && npm run test:next-11 && npm run test:next-12 && npm run test:next-12.2 && npm run test:next-12.latest && npm run test:next-13 && npm run test:next-13.5","test:integration:ci":"npm run test:integration:install && npm run test:integration","test:next-12.latest":"cd test/next-12.latest && npm test","test:integration:install":"(cd test/example-app && npm i); (cd test/next-10 && npm i); (cd test/next-11 && npm i); (cd test/next-12 && npm i); (cd test/next-12.2+ && npm i); (cd test/next-12.latest && npm i); (cd test/next-13 && npm i); (cd test/next-13.5 && npm i)"},"_npmUser":{"name":"cubbic","email":"danpopa1998@gmail.com"},"repository":{"url":"git+https://github.com/cubbk/next-router-mock.git","type":"git"},"_npmVersion":"10.7.0","description":"Mock implementation of the Next.js Router","directories":{},"_nodeVersion":"18.20.3","_hasShrinkwrap":false,"devDependencies":{"jest":"^26.6.3","next":"^13.5.1","react":"^18.2.0","doctoc":"^2.2.0","rimraf":"^3.0.2","ts-jest":"^26.4.4","prettier":"^2.2.1","react-dom":"^18.2.0","typescript":"^4.9.5","@types/jest":"^26.0.20","@changesets/cli":"^2.26.2","react-test-renderer":"^18.2.0","@testing-library/react":"^13.4.0"},"peerDependencies":{"next":">=10.0.0","react":">=17.0.0"},"_npmOperationalInternal":{"tmp":"tmp/next-router-mock_0.9.13_1736345267082_0.3870722671135003","host":"s3://npm-registry-packages-npm-production"}},"0.10.1":{"name":"@cubbk/next-router-mock","version":"0.10.1","keywords":["react","next","next.js","nextjs","router","mock","test","testing"],"author":"","license":"MIT","_id":"@cubbk/next-router-mock@0.10.1","maintainers":[{"name":"cubbic","email":"danpopa1998@gmail.com"}],"homepage":"https://github.com/cubbk/next-router-mock#readme","bugs":{"url":"https://github.com/cubbk/next-router-mock/issues"},"dist":{"shasum":"426c56e12dd7ca6d96b1bb01d1c8a1234b3b932d","tarball":"https://registry.npmjs.org/@cubbk/next-router-mock/-/next-router-mock-0.10.1.tgz","fileCount":113,"integrity":"sha512-0bvcVbkaFQNx6jN0C1TyGxQeSj3rJpmx4X0vR312vFzy/YoMiNWqzbxwIPpSMCBAkPQ5wKD5ztoOrdf7zHXuaA==","signatures":[{"sig":"MEUCIEBw3ZdkFacChEJB/dNZn+wzz3h0Q4kZpKmWypGdgFXVAiEAkdckJE9f6e7RhIQfoGKXDWLQ9AlgyFa2mm+lJT5whtI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":160123},"main":"dist/index","types":"./dist/index.d.ts","gitHead":"9a0184efbf15cea141df305b15178fca1de1a676","scripts":{"docs":"doctoc README.md","lint":"prettier --list-different src","test":"jest","build":"npm run clean && tsc --project tsconfig.build.json","clean":"rimraf dist","checks":"npm run docs && npm run lint && npm run test && npm run build && npm run typecheck && npm run test:integration","release":"changeset publish","lint:fix":"prettier --write src","typecheck":"tsc --noEmit","prerelease":"npm run build","preversion":"npm run checks","test:watch":"jest --watch","build:watch":"npm run build -- --watch","test:exports":"cd test/test-exports && npm test","test:next-10":"cd test/next-10 && npm test","test:next-11":"cd test/next-11 && npm test","test:next-12":"cd test/next-12 && npm test","test:next-13":"cd test/next-13 && npm test","prepublishOnly":"npm run build","test:next-12.2":"cd test/next-12.2+ && npm test","test:next-13.5":"cd test/next-13.5 && npm test","test:example-app":"cd test/example-app && npm test","test:integration":"npm run build && npm run test:exports && npm run test:example-app && npm run test:next-10 && npm run test:next-11 && npm run test:next-12 && npm run test:next-12.2 && npm run test:next-12.latest && npm run test:next-13 && npm run test:next-13.5","test:integration:ci":"npm run test:integration:install && npm run test:integration","test:next-12.latest":"cd test/next-12.latest && npm test","test:integration:install":"(cd test/example-app && npm i); (cd test/next-10 && npm i); (cd test/next-11 && npm i); (cd test/next-12 && npm i); (cd test/next-12.2+ && npm i); (cd test/next-12.latest && npm i); (cd test/next-13 && npm i); (cd test/next-13.5 && npm i)"},"_npmUser":{"name":"cubbic","email":"danpopa1998@gmail.com"},"repository":{"url":"git+https://github.com/cubbk/next-router-mock.git","type":"git"},"_npmVersion":"10.7.0","description":"Mock implementation of the Next.js Router","directories":{},"_nodeVersion":"18.20.3","_hasShrinkwrap":false,"devDependencies":{"jest":"^26.6.3","next":"^13.5.1","react":"^18.2.0","doctoc":"^2.2.0","rimraf":"^3.0.2","ts-jest":"^26.4.4","prettier":"^2.2.1","react-dom":"^18.2.0","typescript":"^4.9.5","@types/jest":"^26.0.20","@changesets/cli":"^2.26.2","react-test-renderer":"^18.2.0","@testing-library/react":"^13.4.0"},"peerDependencies":{"next":">=10.0.0","react":">=17.0.0"},"_npmOperationalInternal":{"tmp":"tmp/next-router-mock_0.10.1_1736439419234_0.3565725250498186","host":"s3://npm-registry-packages-npm-production"}},"0.10.2":{"name":"@cubbk/next-router-mock","version":"0.10.2","keywords":["react","next","next.js","nextjs","router","mock","test","testing"],"author":"","license":"MIT","_id":"@cubbk/next-router-mock@0.10.2","maintainers":[{"name":"cubbic","email":"danpopa1998@gmail.com"}],"homepage":"https://github.com/cubbk/next-router-mock#readme","bugs":{"url":"https://github.com/cubbk/next-router-mock/issues"},"dist":{"shasum":"a3ab9819bd959cd4210acc07c8c997c28ae9c685","tarball":"https://registry.npmjs.org/@cubbk/next-router-mock/-/next-router-mock-0.10.2.tgz","fileCount":113,"integrity":"sha512-LFveXpu6bPQCt6nuphrjzkeze6WwcOd7+cEqTBN706wKmUcBnUB91g2/DM4VF3AmkckD1iIYCW4R0DGC175tcQ==","signatures":[{"sig":"MEUCIQCJMlxbNDubicM7FQ7EjWorPULPLszyi0XjBGx9McSGYAIgZgFfh5Yo4mzz11pmVOgB4AzP1aK9OQxj2SWWsdfu2QY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":160122},"main":"dist/index","types":"./dist/index.d.ts","gitHead":"9a0184efbf15cea141df305b15178fca1de1a676","scripts":{"docs":"doctoc README.md","lint":"prettier --list-different src","test":"jest","build":"npm run clean && tsc --project tsconfig.build.json","clean":"rimraf dist","checks":"npm run docs && npm run lint && npm run test && npm run build && npm run typecheck && npm run test:integration","release":"changeset publish","lint:fix":"prettier --write src","typecheck":"tsc --noEmit","prerelease":"npm run build","preversion":"npm run checks","test:watch":"jest --watch","build:watch":"npm run build -- --watch","test:exports":"cd test/test-exports && npm test","test:next-10":"cd test/next-10 && npm test","test:next-11":"cd test/next-11 && npm test","test:next-12":"cd test/next-12 && npm test","test:next-13":"cd test/next-13 && npm test","prepublishOnly":"npm run build","test:next-12.2":"cd test/next-12.2+ && npm test","test:next-13.5":"cd test/next-13.5 && npm test","test:example-app":"cd test/example-app && npm test","test:integration":"npm run build && npm run test:exports && npm run test:example-app && npm run test:next-10 && npm run test:next-11 && npm run test:next-12 && npm run test:next-12.2 && npm run test:next-12.latest && npm run test:next-13 && npm run test:next-13.5","test:integration:ci":"npm run test:integration:install && npm run test:integration","test:next-12.latest":"cd test/next-12.latest && npm test","test:integration:install":"(cd test/example-app && npm i); (cd test/next-10 && npm i); (cd test/next-11 && npm i); (cd test/next-12 && npm i); (cd test/next-12.2+ && npm i); (cd test/next-12.latest && npm i); (cd test/next-13 && npm i); (cd test/next-13.5 && npm i)"},"_npmUser":{"name":"cubbic","email":"danpopa1998@gmail.com"},"repository":{"url":"git+https://github.com/cubbk/next-router-mock.git","type":"git"},"_npmVersion":"10.7.0","description":"Mock implementation of the Next.js Router","directories":{},"_nodeVersion":"18.20.3","_hasShrinkwrap":false,"devDependencies":{"jest":"^26.6.3","next":"^13.5.1","react":"^18.2.0","doctoc":"^2.2.0","rimraf":"^3.0.2","ts-jest":"^26.4.4","prettier":"^2.2.1","react-dom":"^18.2.0","typescript":"^4.9.5","@types/jest":"^26.0.20","@changesets/cli":"^2.26.2","react-test-renderer":"^18.2.0","@testing-library/react":"^13.4.0"},"peerDependencies":{"next":">=10.0.0","react":">=17.0.0"},"_npmOperationalInternal":{"tmp":"tmp/next-router-mock_0.10.2_1736439553115_0.20382325727349038","host":"s3://npm-registry-packages-npm-production"}},"0.10.3":{"name":"@cubbk/next-router-mock","version":"0.10.3","keywords":["react","next","next.js","nextjs","router","mock","test","testing"],"author":"","license":"MIT","_id":"@cubbk/next-router-mock@0.10.3","maintainers":[{"name":"cubbic","email":"danpopa1998@gmail.com"}],"homepage":"https://github.com/cubbk/next-router-mock#readme","bugs":{"url":"https://github.com/cubbk/next-router-mock/issues"},"dist":{"shasum":"2d41c44f0782a36d84d968ab18f9df7b4ed37982","tarball":"https://registry.npmjs.org/@cubbk/next-router-mock/-/next-router-mock-0.10.3.tgz","fileCount":113,"integrity":"sha512-ATVRLaV24zXGK97UKtyfqMQYa6YSc9RU3lpIz1bFOmcesxA0RCh2g5GAZrGtMedsbp35xfuLacrqCOEE0A+8qw==","signatures":[{"sig":"MEQCIHagv+AxY4aBduNtdOmizrUXg/UjA1+bf9HPf1kW3PbUAiB9fYfMtpOeQ0hpuM3yQL86FYR1QRgdyfh909KZdw71aw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":162205},"main":"dist/index","types":"./dist/index.d.ts","exports":{".":"./dist/index.js","./navigation":"./dist/navigation/index.js"},"gitHead":"3904d8ac52d0855cc764df30af47db6ebed314c8","scripts":{"docs":"doctoc README.md","lint":"prettier --list-different src","test":"jest","build":"npm run clean && tsc --project tsconfig.build.json","clean":"rimraf dist","checks":"npm run docs && npm run lint && npm run test && npm run build && npm run typecheck && npm run test:integration","release":"changeset publish","lint:fix":"prettier --write src","typecheck":"tsc --noEmit","prerelease":"npm run build","preversion":"npm run checks","test:watch":"jest --watch","build:watch":"npm run build -- --watch","test:exports":"cd test/test-exports && npm test","test:next-10":"cd test/next-10 && npm test","test:next-11":"cd test/next-11 && npm test","test:next-12":"cd test/next-12 && npm test","test:next-13":"cd test/next-13 && npm test","prepublishOnly":"npm run build","test:next-12.2":"cd test/next-12.2+ && npm test","test:next-13.5":"cd test/next-13.5 && npm test","test:example-app":"cd test/example-app && npm test","test:integration":"npm run build && npm run test:exports && npm run test:example-app && npm run test:next-10 && npm run test:next-11 && npm run test:next-12 && npm run test:next-12.2 && npm run test:next-12.latest && npm run test:next-13 && npm run test:next-13.5","test:integration:ci":"npm run test:integration:install && npm run test:integration","test:next-12.latest":"cd test/next-12.latest && npm test","test:integration:install":"(cd test/example-app && npm i); (cd test/next-10 && npm i); (cd test/next-11 && npm i); (cd test/next-12 && npm i); (cd test/next-12.2+ && npm i); (cd test/next-12.latest && npm i); (cd test/next-13 && npm i); (cd test/next-13.5 && npm i)"},"_npmUser":{"name":"cubbic","email":"danpopa1998@gmail.com"},"repository":{"url":"git+https://github.com/cubbk/next-router-mock.git","type":"git"},"_npmVersion":"10.7.0","description":"Mock implementation of the Next.js Router","directories":{},"_nodeVersion":"18.20.3","_hasShrinkwrap":false,"devDependencies":{"jest":"^26.6.3","next":"^13.5.1","react":"^18.2.0","doctoc":"^2.2.0","rimraf":"^3.0.2","ts-jest":"^26.4.4","prettier":"^2.2.1","react-dom":"^18.2.0","typescript":"^4.9.5","@types/jest":"^26.0.20","@changesets/cli":"^2.26.2","react-test-renderer":"^18.2.0","@testing-library/react":"^13.4.0"},"peerDependencies":{"next":">=10.0.0","react":">=17.0.0"},"_npmOperationalInternal":{"tmp":"tmp/next-router-mock_0.10.3_1746710874243_0.27637225876638505","host":"s3://npm-registry-packages-npm-production"}},"0.11.0":{"name":"@cubbk/next-router-mock","version":"0.11.0","description":"Mock implementation of the Next.js Router","main":"dist/index","exports":{".":"./dist/index.js","./navigation":"./dist/navigation/index.js"},"scripts":{"checks":"npm run docs && npm run lint && npm run test && npm run build && npm run typecheck && npm run test:integration","lint":"prettier --list-different src","lint:fix":"prettier --write src","docs":"doctoc README.md","test":"jest","test:watch":"jest --watch","test:integration:ci":"npm run test:integration:install && npm run test:integration","test:integration:install":"(cd test/example-app && npm i); (cd test/next-10 && npm i); (cd test/next-11 && npm i); (cd test/next-12 && npm i); (cd test/next-12.2+ && npm i); (cd test/next-12.latest && npm i); (cd test/next-13 && npm i); (cd test/next-13.5 && npm i)","test:integration":"npm run build && npm run test:exports && npm run test:example-app && npm run test:next-10 && npm run test:next-11 && npm run test:next-12 && npm run test:next-12.2 && npm run test:next-12.latest && npm run test:next-13 && npm run test:next-13.5","test:example-app":"cd test/example-app && npm test","test:exports":"cd test/test-exports && npm test","test:next-10":"cd test/next-10 && npm test","test:next-11":"cd test/next-11 && npm test","test:next-12":"cd test/next-12 && npm test","test:next-12.2":"cd test/next-12.2+ && npm test","test:next-12.latest":"cd test/next-12.latest && npm test","test:next-13":"cd test/next-13 && npm test","test:next-13.5":"cd test/next-13.5 && npm test","typecheck":"tsc --noEmit","build":"npm run clean && tsc --project tsconfig.build.json","clean":"rimraf dist","build:watch":"npm run build -- --watch","prepublishOnly":"npm run build","preversion":"npm run checks","prerelease":"npm run build","release":"changeset publish"},"repository":{"type":"git","url":"git+https://github.com/cubbk/next-router-mock.git"},"keywords":["react","next","next.js","nextjs","router","mock","test","testing"],"author":"","license":"MIT","bugs":{"url":"https://github.com/cubbk/next-router-mock/issues"},"homepage":"https://github.com/cubbk/next-router-mock#readme","peerDependencies":{"next":">=10.0.0","react":">=17.0.0"},"devDependencies":{"@changesets/cli":"^2.26.2","@testing-library/react":"^13.4.0","@types/jest":"^26.0.20","doctoc":"^2.2.0","jest":"^26.6.3","next":"^13.5.1","prettier":"^2.2.1","react":"^18.2.0","react-dom":"^18.2.0","react-test-renderer":"^18.2.0","rimraf":"^3.0.2","ts-jest":"^26.4.4","typescript":"^4.9.5"},"_id":"@cubbk/next-router-mock@0.11.0","gitHead":"994a0cd57d2eb6886f0a10d40d04e732a616b3b3","types":"./dist/index.d.ts","_nodeVersion":"18.20.3","_npmVersion":"10.7.0","dist":{"integrity":"sha512-oNzSNfGXpe1f5Gb9CKUeBWi6mkLBW2Gu2GfLJuXQlZE7/nOtdTyvHDdX3hvHcnHQ07XKka9TMAgINihKi54XhQ==","shasum":"2fc32461500cb4b4492d8d1a79d23fab9bdf27a1","tarball":"https://registry.npmjs.org/@cubbk/next-router-mock/-/next-router-mock-0.11.0.tgz","fileCount":113,"unpackedSize":162895,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCbaeX8orO7KFnP9SEjnPiDlEpNRdPuq1b5qfXAtHh5ZwIhAJlsxgKW8YeHCn57nAuLWcp0Ih8v9BMMn/H0XCteOjkX"}]},"_npmUser":{"name":"cubbic","email":"danpopa1998@gmail.com"},"directories":{},"maintainers":[{"name":"cubbic","email":"danpopa1998@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/next-router-mock_0.11.0_1746712118366_0.9272998952447131"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-08T14:07:46.959Z","modified":"2025-05-08T13:48:38.750Z","0.9.13":"2025-01-08T14:07:47.261Z","0.10.1":"2025-01-09T16:16:59.403Z","0.10.2":"2025-01-09T16:19:13.314Z","0.10.3":"2025-05-08T13:27:54.445Z","0.11.0":"2025-05-08T13:48:38.533Z"},"bugs":{"url":"https://github.com/cubbk/next-router-mock/issues"},"license":"MIT","homepage":"https://github.com/cubbk/next-router-mock#readme","keywords":["react","next","next.js","nextjs","router","mock","test","testing"],"repository":{"type":"git","url":"git+https://github.com/cubbk/next-router-mock.git"},"description":"Mock implementation of the Next.js Router","maintainers":[{"name":"cubbic","email":"danpopa1998@gmail.com"}],"readme":"# `@cubbk/next-router-mock`\n\nAn implementation of the Next.js Router that keeps the state of the \"URL\" in memory (does not read or write to the\naddress bar). Useful in **tests** and **Storybook**.\nInspired by [`react-router > MemoryRouter`](https://github.com/remix-run/react-router/blob/main/docs/router-components/memory-router.md).\n\nTested with NextJS v13, v12, v11, and v10.\n\nInstall via NPM: `npm install --save-dev @cubbk/next-router-mock`\n\nFor usage with `next/navigation` jump to [Usage with next/navigation Beta](#usage-with-nextnavigation-beta)\n\n<!-- START doctoc generated TOC please keep comment here to allow auto update -->\n<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->\n\n- [Usage with Jest](#usage-with-jest)\n    - [Jest Configuration](#jest-configuration)\n    - [Jest Example](#jest-example)\n- [Usage with Storybook](#usage-with-storybook)\n    - [Storybook Configuration](#storybook-configuration)\n    - [Storybook Example](#storybook-example)\n- [Compatibility with `next/link`](#compatibility-with-nextlink)\n    - [Example: `next/link` with React Testing Library](#example-nextlink-with-react-testing-library)\n    - [Example: `next/link` with Enzyme](#example-nextlink-with-enzyme)\n    - [Example: `next/link` with Storybook](#example-nextlink-with-storybook)\n- [Dynamic Routes](#dynamic-routes)\n- [Sync vs Async](#sync-vs-async)\n- [Supported Features](#supported-features)\n  - [Not yet supported](#not-yet-supported)\n- [Usage with next/navigation Beta](#usage-with-nextnavigation-beta)\n  - [Usage with Jest](#usage-with-jest-1)\n    - [Jest Configuration](#jest-configuration-1)\n    - [Jest Example](#jest-example-1)\n    - [Supported](#supported)\n    - [Not supported yet](#not-supported-yet)\n\n<!-- END doctoc generated TOC please keep comment here to allow auto update -->\n\n# Usage with Jest\n\n### Jest Configuration\n\nFor unit tests, the `@cubbk/next-router-mock` module can be used as a drop-in replacement for `next/router`:\n\n```js\njest.mock(\"next/router\", () => require(\"@cubbk/next-router-mock\"));\n```\n\nYou can do this once per spec file, or you can [do this globally using `setupFilesAfterEnv`](https://jestjs.io/docs/configuration/#setupfilesafterenv-array).\n\n### Jest Example\n\nIn your tests, use the router from `@cubbk/next-router-mock` to set the current URL and to make assertions.\n\n```jsx\nimport { useRouter } from \"next/router\";\nimport { render, screen, fireEvent } from \"@testing-library/react\";\nimport mockRouter from \"@cubbk/next-router-mock\";\n\njest.mock(\"next/router\", () => jest.requireActual(\"@cubbk/next-router-mock\"));\n\nconst ExampleComponent = ({ href = \"\" }) => {\n  const router = useRouter();\n  return <button onClick={() => router.push(href)}>The current route is: \"{router.asPath}\"</button>;\n};\n\ndescribe(\"@cubbk/next-router-mock\", () => {\n  it(\"mocks the useRouter hook\", () => {\n    // Set the initial url:\n    mockRouter.push(\"/initial-path\");\n\n    // Render the component:\n    render(<ExampleComponent href=\"/foo?bar=baz\" />);\n    expect(screen.getByRole(\"button\")).toHaveText('The current route is: \"/initial-path\"');\n\n    // Click the button:\n    fireEvent.click(screen.getByRole(\"button\"));\n\n    // Ensure the router was updated:\n    expect(mockRouter).toMatchObject({\n      asPath: \"/foo?bar=baz\",\n      pathname: \"/foo\",\n      query: { bar: \"baz\" },\n    });\n  });\n});\n```\n\n# Usage with Storybook\n\n### Storybook Configuration\n\nGlobally enable `@cubbk/next-router-mock` by adding the following webpack alias to your Storybook configuration.\n\nIn `.storybook/main.js` add:\n\n```js\nmodule.exports = {\n  webpackFinal: async (config, { configType }) => {\n    config.resolve.alias = {\n      ...config.resolve.alias,\n      \"next/router\": \"@cubbk/next-router-mock\",\n    };\n    return config;\n  },\n};\n```\n\nThis ensures that all your components that use `useRouter` will work in Storybook. If you also need to test `next/link`, please see the section [Example: **`next/link` with Storybook**](#example-nextlink-with-storybook).\n\n### Storybook Example\n\nIn your individual stories, you might want to mock the current URL (eg. for testing an \"ActiveLink\" component), or you might want to log `push/replace` actions. You can do this by wrapping your stories with the `<MemoryRouterProvider>` component.\n\n```jsx\n// ActiveLink.story.jsx\nimport { action } from \"@storybook/addon-actions\";\nimport { MemoryRouterProvider } from \"@cubbk/next-router-mock/MemoryRouterProvider/next-13\";\nimport { ActiveLink } from \"./active-link\";\n\nexport const ExampleStory = () => (\n  <MemoryRouterProvider url=\"/active\" onPush={action(\"router.push\")}>\n    <ActiveLink href=\"/example\">Not Active</ActiveLink>\n    <ActiveLink href=\"/active\">Active</ActiveLink>\n  </MemoryRouterProvider>\n);\n```\n\n> Be sure to import from **a matching Next.js version**:\n>\n> ```\n> import { MemoryRouterProvider }\n>   from '@cubbk/next-router-mock/MemoryRouterProvider/next-13.5';\n> ```\n>\n> Choose from `next-13.5`, `next-13`, `next-12`, or `next-11`.\n\nThe `MemoryRouterProvider` has the following optional properties:\n\n- `url` (`string` or `object`) sets the current route's URL\n- `async` enables async mode, if necessary (see \"Sync vs Async\" for details)\n- Events:\n  - `onPush(url, { shallow })`\n  - `onReplace(url, { shallow })`\n  - `onRouteChangeStart(url, { shallow })`\n  - `onRouteChangeComplete(url, { shallow })`\n\n# Compatibility with `next/link`\n\nTo use `@cubbk/next-router-mock` with `next/link`, you must use a `<MemoryRouterProvider>` to wrap the test component.\n\n### Example: `next/link` with React Testing Library\n\nWhen rendering, simply supply the option `{ wrapper: MemoryRouterProvider }`\n\n```jsx\nimport { render } from \"@testing-library/react\";\nimport NextLink from \"next/link\";\n\nimport mockRouter from \"@cubbk/next-router-mock\";\nimport { MemoryRouterProvider } from \"@cubbk/next-router-mock/MemoryRouterProvider\";\n\nit(\"NextLink can be rendered\", () => {\n  render(<NextLink href=\"/example\">Example Link</NextLink>, { wrapper: MemoryRouterProvider });\n  fireEvent.click(screen.getByText(\"Example Link\"));\n  expect(mockRouter.asPath).toEqual(\"/example\");\n});\n```\n\n### Example: `next/link` with Enzyme\n\nWhen rendering, simply supply the option `{ wrapperComponent: MemoryRouterProvider }`\n\n```jsx\nimport { shallow } from \"enzyme\";\nimport NextLink from \"next/link\";\n\nimport mockRouter from \"@cubbk/next-router-mock\";\nimport { MemoryRouterProvider } from \"@cubbk/next-router-mock/MemoryRouterProvider\";\n\nit(\"NextLink can be rendered\", () => {\n  const wrapper = shallow(<NextLink href=\"/example\">Example Link</NextLink>, {\n    wrapperComponent: MemoryRouterProvider,\n  });\n\n  wrapper.find(\"a\").simulate(\"click\");\n\n  expect(mockRouter.asPath).to.equal(\"/example\");\n});\n```\n\n### Example: `next/link` with Storybook\n\nIn Storybook, you must wrap your component with the `<MemoryRouterProvider>` component (with optional `url` set).\n\n```jsx\n// example.story.jsx\nimport NextLink from \"next/link\";\nimport { action } from \"@storybook/addon-actions\";\n\nimport { MemoryRouterProvider } from \"@cubbk/next-router-mock/MemoryRouterProvider/next-13.5\";\n\nexport const ExampleStory = () => (\n  <MemoryRouterProvider url=\"/initial\">\n    <NextLink href=\"/example\">Example Link</NextLink>\n  </MemoryRouterProvider>\n);\n```\n\nThis can be done inline (as above).  \nIt can also be implemented as a `decorator`, which can be per-Story, per-Component, or Global (see [Storybook Decorators Documentation](https://storybook.js.org/docs/react/writing-stories/decorators) for details).  \nGlobal example:\n\n```\n// .storybook/preview.js\nimport { MemoryRouterProvider } from '@cubbk/next-router-mock/MemoryRouterProvider';\n\nexport const decorators = [\n  (Story) => <MemoryRouterProvider><Story /></MemoryRouterProvider>\n];\n```\n\n# Dynamic Routes\n\nBy default, `@cubbk/next-router-mock` does not know about your dynamic routes (eg. files like `/pages/[id].js`).\nTo test code that uses dynamic routes, you must add the routes manually, like so:\n\n```typescript\nimport mockRouter from \"@cubbk/next-router-mock\";\nimport { createDynamicRouteParser } from \"@cubbk/next-router-mock/dynamic-routes\";\n\nmockRouter.useParser(\n  createDynamicRouteParser([\n    // These paths should match those found in the `/pages` folder:\n    \"/[id]\",\n    \"/static/path\",\n    \"/[dynamic]/path\",\n    \"/[...catchAll]/path\",\n  ])\n);\n\n// Example test:\nit(\"should parse dynamic routes\", () => {\n  mockRouter.push(\"/FOO\");\n  expect(mockRouter).toMatchObject({\n    pathname: \"/[id]\",\n    query: { id: \"FOO\" },\n  });\n});\n```\n\n# Sync vs Async\n\nBy default, `@cubbk/next-router-mock` handles route changes synchronously. This is convenient for testing, and works for most\nuse-cases.  \nHowever, Next normally handles route changes asynchronously, and in certain cases you might actually rely on that\nbehavior. If that's the case, you can use `@cubbk/next-router-mock/async`. Tests will need to account for the async behavior\ntoo; for example:\n\n```jsx\nit(\"next/link can be tested too\", async () => {\n  render(\n    <NextLink href=\"/example?foo=bar\">\n      <a>Example Link</a>\n    </NextLink>\n  );\n  fireEvent.click(screen.getByText(\"Example Link\"));\n  await waitFor(() => {\n    expect(singletonRouter).toMatchObject({\n      asPath: \"/example?foo=bar\",\n      pathname: \"/example\",\n      query: { foo: \"bar\" },\n    });\n  });\n});\n```\n\n# Supported Features\n\n- `useRouter()`\n- `withRouter(Component)`\n- `router.push(url, as?, options?)`\n- `router.replace(url, as?, options?)`\n- `router.route`\n- `router.pathname`\n- `router.asPath`\n- `router.query`\n- Works with `next/link` (see Jest notes)\n- `router.events` supports:\n  - `routeChangeStart(url, { shallow })`\n  - `routeChangeComplete(url, { shallow })`\n  - `hashChangeStart(url, { shallow })`\n  - `hashChangeComplete(url, { shallow })`\n\n## Not yet supported\n\nPRs welcome!  \nThese fields just have default values; these methods do nothing.\n\n- `router.isReady`\n- `router.basePath`\n- `router.isFallback`\n- `router.isLocaleDomain`\n- `router.locale`\n- `router.locales`\n- `router.defaultLocale`\n- `router.domainLocales`\n- `router.prefetch()`\n- `router.back()`\n- `router.beforePopState(cb)`\n- `router.reload()`\n- `router.events` not implemented:\n  - `routeChangeError`\n  - `beforeHistoryChange`\n\n# Usage with next/navigation Beta\n\n## Usage with Jest\n\n### Jest Configuration\n\nFor unit tests, the `@cubbk/next-router-mock/navigation` module can be used as a drop-in replacement for `next/navigation`:\n\n```js\njest.mock(\"next/navigation\", () => require(\"@cubbk/@cubbk/next-router-mock/navigation\"));\n```\n\nYou can do this once per spec file, or you can [do this globally using `setupFilesAfterEnv`](https://jestjs.io/docs/configuration/#setupfilesafterenv-array).\n\n### Jest Example\n\nIn your tests, use the router from `@cubbk/next-router-mock` to set the current URL and to make assertions.\n\n```jsx\nimport mockRouter from \"@cubbk/@cubbk/next-router-mock\";\nimport { render, screen, fireEvent } from \"@testing-library/react\";\nimport { usePathname, useRouter } from \"next/navigation\";\n\njest.mock(\"next/navigation\", () => jest.requireActual(\"@cubbk/@cubbk/next-router-mock/navigation\"));\n\nconst ExampleComponent = ({ href = \"\" }) => {\n  const router = useRouter();\n  const pathname = usePathname();\n  return <button onClick={() => router.push(href)}>The current route is: {pathname}</button>;\n};\n\ndescribe(\"@cubbk/next-router-mock\", () => {\n  it(\"mocks the useRouter hook\", () => {\n    // Set the initial url:\n    mockRouter.push(\"/initial-path\");\n\n    // Render the component:\n    render(<ExampleComponent href=\"/foo?bar=baz\" />);\n    expect(screen.getByRole(\"button\")).toHaveTextContent(\"The current route is: /initial-path\");\n\n    // Click the button:\n    fireEvent.click(screen.getByRole(\"button\"));\n\n    // Ensure the router was updated:\n    expect(mockRouter).toMatchObject({\n      asPath: \"/foo?bar=baz\",\n      pathname: \"/foo\",\n      query: { bar: \"baz\" },\n    });\n  });\n});\n```\n\n### Supported\n\n- useRouter\n- usePathname\n- useParams\n- useSearchParams\n\n### Not supported yet\n\n- Storybook\n- useSelectedLayoutSegment, useSelectedLayoutSegments\n- non-hook utils in next/navigation\n","readmeFilename":"README.md"}