{"id":17767310,"url":"https://github.com/jamiebuilds/react-markers","last_synced_at":"2025-03-15T13:31:15.806Z","repository":{"id":57334345,"uuid":"93451916","full_name":"jamiebuilds/react-markers","owner":"jamiebuilds","description":"Add markers to your React components for easy testing with actual DOM elements","archived":false,"fork":false,"pushed_at":"2018-04-04T21:13:13.000Z","size":54,"stargazers_count":79,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-12T21:02:04.825Z","etag":null,"topics":["dom","react","selenium","testing"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamiebuilds.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-05T22:15:22.000Z","updated_at":"2023-12-31T01:35:01.000Z","dependencies_parsed_at":"2022-08-31T16:44:03.937Z","dependency_job_id":null,"html_url":"https://github.com/jamiebuilds/react-markers","commit_stats":null,"previous_names":["thejameskyle/react-markers"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiebuilds%2Freact-markers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiebuilds%2Freact-markers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiebuilds%2Freact-markers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiebuilds%2Freact-markers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamiebuilds","download_url":"https://codeload.github.com/jamiebuilds/react-markers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243293745,"owners_count":20268140,"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":["dom","react","selenium","testing"],"created_at":"2024-10-26T20:46:02.479Z","updated_at":"2025-03-15T13:31:15.431Z","avatar_url":"https://github.com/jamiebuilds.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-markers\n\n\u003e Add markers to your React components for easy testing with actual DOM elements\n\n## Installation\n\n```sh\nyarn add react-markers\n```\n\n## Usage\n\nCreate static elements to use in your component, and export them from your\nmodule.\n\n```js\n// ConfirmPage.js\nimport marker from 'react-markers';\n\nexport const confirmForm = marker();\nexport const confirmButton = marker();\n\nexport default function ConfirmPage() {\n  return (\n    \u003cform onSubmit={...} {...confirmForm}\u003e\n      \u003ch1\u003eConfirm action\u003c/h1\u003e\n      \u003cp\u003eThis will perform an action\u003c/p\u003e\n      \u003cbutton type=\"submit\" {...confirmButton}\u003eSubmit\u003c/button\u003e\n    \u003c/form\u003e\n  );\n}\n```\n\nThen in your tests, you can use `find()` and `findAll()` to lookup these\nmarkers from the DOM.\n\n```js\n// ConfirmPage.test.js\nimport { render } from 'react-dom';\nimport ConfirmPage, { confirmForm, confirmButton } from './ConfirmPage';\nimport marker from 'react-markers';\n\nconst container = document.getElementById('test-container');\n\nrender(\u003cLoginPage/\u003e, container);\n\nlet form = marker.find(container, confirmForm); // \u003cform\u003e\nlet btn = marker.find(form, confirmButton); // \u003cbutton type=\"submit\"\u003e\n```\n\nBe sure that `process.env.NODE_ENV` is set to `\"test\"` when running your tests.\n\n## API\n\n#### `marker()`\n\nIn test environments this returns an object of props to pass to your DOM\nelements. In other environments it returns `null`.\n\n```js\nexport const myButton = marker();\nexport default function MyButton() {\n  return \u003cbutton {...myButton}/\u003e;\n}\n```\n\n#### find(element, marker)\n\n`element` is a DOM element and `marker` is the value returned by `marker()`.\n\nIt returns either the matched DOM element or `null`.\n\n```js\nimport MyButton, { myButton } from './MyButton';\nrender(\u003cMyButton/\u003e, container);\nfindAll(container, myButton); // HTMLElement | null\n```\n\n#### findAll(element, marker)\n\n`element` is a DOM element and `marker` is the value returned by `marker()`.\n\nIt returns a `NodeList`.\n\n```js\nimport MyButton, { myButton } from './MyButton';\nrender(\u003cMyButton/\u003e, container);\nfindAll(container, myButton); // NodeList\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamiebuilds%2Freact-markers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamiebuilds%2Freact-markers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamiebuilds%2Freact-markers/lists"}