{"id":21654781,"url":"https://github.com/localvoid/jest-hooks-dom","last_synced_at":"2026-05-16T18:02:40.021Z","repository":{"id":39407030,"uuid":"263032982","full_name":"localvoid/jest-hooks-dom","owner":"localvoid","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-06T05:34:56.000Z","size":1353,"stargazers_count":1,"open_issues_count":15,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-25T06:25:23.146Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"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/localvoid.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":"2020-05-11T12:15:26.000Z","updated_at":"2020-05-12T05:03:43.000Z","dependencies_parsed_at":"2023-02-05T10:46:20.964Z","dependency_job_id":null,"html_url":"https://github.com/localvoid/jest-hooks-dom","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/localvoid%2Fjest-hooks-dom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Fjest-hooks-dom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Fjest-hooks-dom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Fjest-hooks-dom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/localvoid","download_url":"https://codeload.github.com/localvoid/jest-hooks-dom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244554121,"owners_count":20471173,"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":[],"created_at":"2024-11-25T08:29:03.532Z","updated_at":"2025-10-04T15:42:04.028Z","avatar_url":"https://github.com/localvoid.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"507\" height=\"351\" src=\"https://localvoid.github.io/jest-hooks-dom/example.png\"\u003e\n\u003c/p\u003e\n\n`jest-hooks-dom` is a collection of [hooks](https://github.com/localvoid/jest-hooks) for DOM testing with\n[Jest](https://jestjs.io/) library.\n\n## Hooks\n\n### Elements\n\n`useHTMLElement(element, container)` creates a new HTML element before each test and optionally mounts it to the\ncontainer. After each test HTML element is removed from container.\n\n`useSVGElement(element, container)` creates a new SVG element before each test and optionally mounts it to the\ncontainer. After each test SVG element is removed from container.\n\n`useHTMLTemplate(html, container)` create a new HTML from template before each test and optionally mounts it to the\ncontainer. After each test all root nodes are removed from container.\n\n```js\nconst t = useHTMLTemplate(`\n  \u003cdiv\u003e\n    \u003cspan id=\"a\"\u003eA\u003c/span\u003e\n    \u003cspan id=\"b\"\u003eB\u003c/span\u003e\n  \u003c/div\u003e\n`);\n\ndescribe(\"template\", () =\u003e {\n  it(\"should find all nodes by id\", () =\u003e {\n    expect(t.a.textContent).toBe(\"A\");\n    expect(t.b.textContent).toBe(\"B\");\n  });\n});\n```\n\n### Mutation Tracking\n\n`useDOMMutationTracker()` tracks DOM mutations.\n\nMethods and properties tracked:\n\n - `Document.prototype.createElement`\n - `Document.prototype.createElementNS`\n - `Document.prototype.createTextNode`\n - `Node.prototype.appendChild`\n - `Node.prototype.insertBefore`\n - `Node.prototype.replaceChild`\n - `Node.prototype.removeChild`\n - `Node.prototype.textContent`\n - `Node.prototype.nodeValue`\n - `Element.prototype.innerHTML`\n\n```js\nimport { useModule } from \"jest-hooks\";\nimport { useResetDOM, useHTMLElement, useDOMMutationTracker } from \"jest-hooks-dom\";\n\nuseResetDOM();\nconst root = useHTMLElement();\nconst mutations = useDOMMutationTracker();\nconst ivi = useModule(\"ivi\");\nconst r = (op: Op) =\u003e ivi.render(op, root());\n\ndescribe(\"fragment\", () =\u003e {\n  describe(\"mount\", () =\u003e {\n    test(\"[]\", () =\u003e {\n      r([]);\n      expect(mutations.stats).toMatchSnapshot();\n    });\n  });\n});\n```\n\n### Events\n\n`useResetDOMEventListeners()` tracks all unregistered event listeners and automatically removes them after each test.\n\n### requestAnimationFrame\n\n`useRequestAnimationFrame()` mocks `requestAnimationFrame()` and `cancelAnimationFrame()`, and resets all tasks after\neach test.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalvoid%2Fjest-hooks-dom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocalvoid%2Fjest-hooks-dom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalvoid%2Fjest-hooks-dom/lists"}