{"id":15552404,"url":"https://github.com/bahmutov/test-react-router-v5","last_synced_at":"2025-09-29T01:30:30.771Z","repository":{"id":37581556,"uuid":"254249192","full_name":"bahmutov/test-react-router-v5","owner":"bahmutov","description":"Component tests for apps that use React Router v5","archived":false,"fork":false,"pushed_at":"2024-12-17T20:27:26.000Z","size":407,"stargazers_count":2,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-27T20:11:22.447Z","etag":null,"topics":["cypress-react-unit-test-example"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bahmutov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-09T02:14:56.000Z","updated_at":"2022-05-16T01:18:37.000Z","dependencies_parsed_at":"2023-11-14T23:23:32.831Z","dependency_job_id":"c7af3feb-b6d7-4efa-8159-34674ea9c3ee","html_url":"https://github.com/bahmutov/test-react-router-v5","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Ftest-react-router-v5","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Ftest-react-router-v5/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Ftest-react-router-v5/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Ftest-react-router-v5/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/test-react-router-v5/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234575265,"owners_count":18854927,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cypress-react-unit-test-example"],"created_at":"2024-10-02T14:18:53.897Z","updated_at":"2025-09-29T01:30:30.449Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# test-react-router-v5\n\u003e Component tests for apps that use [React Router v5](https://reacttraining.com/react-router/web/guides/quick-start)\n\n![cypress version](https://img.shields.io/badge/cypress-5.6.0-brightgreen) ![cypress-react-unit-test version](https://img.shields.io/badge/cypress--react--unit--test-4.17.2-brightgreen)\n\nUses [cypress-react-unit-test](https://github.com/bahmutov/cypress-react-unit-test)\n\n- [src/App.spec.js](src/App.spec.js) shows basic routing\n- [src/Nesting.spec.js](src/Nesting.spec.js) shows two level of routing\n- [src/Auth.spec.js](src/Auth.spec.js) takes protected routes for a spin\n- [src/RouteConfig.spec.js](src/RouteConfig.spec.js) passes the list of routes from the test to the component to render\n\n![Route config test](images/route-config.png)\n\n## Common problems\n\n\u003cdetails\u003e\n  \u003csummary\u003eCannot read property 'location' of undefined\u003c/summary\u003e\n  If the test fails with this error from `useContext(Context).location` line, you have probably forgotten to surround the mounted route with the `BrowserRouter` component.\n\n```js\nimport { BrowserRouter } from 'react-router-dom'\n// then in the test mount the component the same way\n// as you would in the \"normal\" mini web application\n// AuthenticatedRoute and NewNote are user code we want to test\nmount(\n  \u003cBrowserRouter\u003e\n    \u003cAuthenticatedRoute\u003e\n      \u003cNewNote /\u003e\n    \u003c/AuthenticatedRoute\u003e\n  \u003c/BrowserRouter\u003e\n)\n```\n\nSee [cypress-react-unit-test#388](https://github.com/bahmutov/cypress-react-unit-test/issues/388) for example\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eCannot read property '...' of null\u003c/summary\u003e\n  If the components inside the route rely on a context, surround the routes with appropriate context provider.\n\n```js\n// AuthenticatedRoute.js\nexport default function AuthenticatedRoute({ children, ...rest }) {\n  const { isAuthenticated } = useAppContext();\n  ...\n}\n// test file\nmount(\n  \u003cBrowserRouter\u003e\n    \u003cAppContext.Provider value={{ isAuthenticated: true, userHasAuthenticated: true }}\u003e\n      \u003cAuthenticatedRoute\u003e...\u003c/AuthenticatedRoute\u003e\n    \u003c/AppContext.Provider\u003e\n  \u003c/BrowserRouter\u003e\n)\n```\n\nSee [cypress-react-unit-test#388](https://github.com/bahmutov/cypress-react-unit-test/issues/388) for example\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Ftest-react-router-v5","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Ftest-react-router-v5","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Ftest-react-router-v5/lists"}