{"id":16296324,"url":"https://github.com/fabioantunes/react-portals-example","last_synced_at":"2026-04-30T02:32:49.764Z","repository":{"id":86555390,"uuid":"145702113","full_name":"FabioAntunes/react-portals-example","owner":"FabioAntunes","description":"Testing React portals with enzyme","archived":false,"fork":false,"pushed_at":"2018-08-22T12:09:44.000Z","size":112,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-27T10:05:46.699Z","etag":null,"topics":["enzyme","enzyme-testing","jsdom","modal","modals","portals","react","react-16","react-portals","testing"],"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/FabioAntunes.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":"2018-08-22T11:51:07.000Z","updated_at":"2019-08-12T03:54:33.000Z","dependencies_parsed_at":"2023-03-13T19:58:27.824Z","dependency_job_id":null,"html_url":"https://github.com/FabioAntunes/react-portals-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/FabioAntunes/react-portals-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabioAntunes%2Freact-portals-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabioAntunes%2Freact-portals-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabioAntunes%2Freact-portals-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabioAntunes%2Freact-portals-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FabioAntunes","download_url":"https://codeload.github.com/FabioAntunes/react-portals-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabioAntunes%2Freact-portals-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262235779,"owners_count":23279566,"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":["enzyme","enzyme-testing","jsdom","modal","modals","portals","react","react-16","react-portals","testing"],"created_at":"2024-10-10T20:22:05.878Z","updated_at":"2026-04-30T02:32:49.731Z","avatar_url":"https://github.com/FabioAntunes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).\n\n## Testing React 16 Portals with enzyme\n\nThis is a repo with an example of a working modal, using React 16 Portals.\n\nThis is the solution for the question and answer that I posted on [stackoverflow](https://stackoverflow.com/questions/48094581/testing-react-portals-with-enzyme)\n\n\n## Running the project\n\nInstall dependencies\n\n```\nyarn|npm install\n```\n\nStart the project\n\n```\nyarn|npm start\n```\n\nRun the tests\n\n```\nyarn|npm test\n```\n\n## Testing portals\n\nSo basically the idea is that for us to test portals we need to modify our `jsdom` so when we use `enzyme` to mount our components, we have the desired div.\nTo modify the default jsdom html all we need to do before running our tests is this:\n\n```javascript\nconst modalRoot = global.document.createElement('div');\nmodalRoot.setAttribute('id', 'modal-root');\nconst body = global.document.querySelector('body');\nbody.appendChild(modalRoot);\n```\n\n\nthe code and the tests are self explanatory.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabioantunes%2Freact-portals-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabioantunes%2Freact-portals-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabioantunes%2Freact-portals-example/lists"}