{"id":21654649,"url":"https://github.com/localvoid/jest-hooks","last_synced_at":"2026-02-20T19:32:14.180Z","repository":{"id":39406633,"uuid":"263015712","full_name":"localvoid/jest-hooks","owner":"localvoid","description":"Jest hooks","archived":false,"fork":false,"pushed_at":"2023-01-06T05:34:35.000Z","size":1411,"stargazers_count":3,"open_issues_count":15,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-15T16:30:02.880Z","etag":null,"topics":["jest"],"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-11T10:52:50.000Z","updated_at":"2021-12-17T17:41:50.000Z","dependencies_parsed_at":"2023-02-05T10:46:16.713Z","dependency_job_id":null,"html_url":"https://github.com/localvoid/jest-hooks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/localvoid/jest-hooks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Fjest-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Fjest-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Fjest-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Fjest-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/localvoid","download_url":"https://codeload.github.com/localvoid/jest-hooks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Fjest-hooks/sbom","scorecard":{"id":596674,"data":{"date":"2025-08-18","repo":{"name":"github.com/localvoid/jest-hooks","commit":"1d49ae5ac8eae255598f6d4d058a7e0dd10c9b6e"},"scorecard":{"version":"v5.2.1-41-g40576783","commit":"40576783fda6698350fcbbeaea760ff827433034"},"score":1.7,"checks":[{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/5 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#dangerous-workflow"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"35 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-xp63-6vf5-xf3v","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-w7rc-rwvf-8q5r","Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/40576783fda6698350fcbbeaea760ff827433034/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T23:18:26.733Z","repository_id":39406633,"created_at":"2025-08-20T23:18:26.733Z","updated_at":"2025-08-20T23:18:26.733Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29661595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-20T16:33:43.953Z","status":"ssl_error","status_checked_at":"2026-02-20T16:33:43.598Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["jest"],"created_at":"2024-11-25T08:28:36.535Z","updated_at":"2026-02-20T19:32:12.504Z","avatar_url":"https://github.com/localvoid.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"574\" height=\"369\" src=\"https://localvoid.github.io/jest-hooks/example.png\"\u003e\n\u003c/p\u003e\n\n`jest-hooks` is a collection of hooks for testing with [Jest](https://jestjs.io/) library.\n\n## Hooks\n\n### State\n\n`useTestState(initState)` creates transient test state. `initState` argument is a function that initializes state before\neach test.\n\n```js\ndescribe(\"state\", () =\u003e {\n  const [get, set] = useTestState(() =\u003e 0);\n\n  it(\"should set state\", () =\u003e {\n    set(1);\n    expect(get()).toBe(1);\n  });\n\n  it(\"should reset state\", () =\u003e {\n    expect(get()).toBe(0);\n  });\n});\n```\n\n`useTestStateProxy(initState)` creates transient state wrapped in a `Proxy` object.\n\n```js\nimport { useTestStateProxy } from \"jest-hooks\";\n\ndescribe(\"state\", () =\u003e {\n  const el = useTestStateProxy((clean) =\u003e {\n    const el = document.createElement(\"div\");\n    document.body.appendChild(el);\n    clean(() =\u003e {\n      el.remove();\n    });\n    return el;\n  });\n\n  it(\"should modify text content\", () =\u003e {\n    el.textContent = \"text\";\n    expect(el.textContent).toBe(\"text\");\n  });\n\n  it(\"should create a new element\", () =\u003e {\n    expect(el.textContent).toBe(\"\");\n  });\n});\n```\n\n### Environment\n\n`useEnv(kev, value)` overrides `process.env` before each tests and restores it to the original value after each test.\n\n```js\nimport { useEnv } from \"jest-hooks\";\n\nfunction throwsInDevMode() {\n  if (process.env.NODE_ENV !== \"production\") {\n    throw Error();\n  }\n}\n\ndescribe(\"development\", () =\u003e {\n  useEnv(\"NODE_ENV\", \"development\");\n\n  it(\"should perform runtime checks in development mode\", () =\u003e {\n    expect(() =\u003e { throwsInDevMode(); }).toThrowError();\n  });\n});\n\ndescribe(\"production\", () =\u003e {\n  useEnv(\"NODE_ENV\", \"production\");\n\n  it(\"should not perform runtime checks in production mode\", () =\u003e {\n    expect(() =\u003e { throwsInDevMode(); }).not.toThrowError();\n  });\n});\n```\n\n### Modules\n\n`useResetModules()` resets modules before each test (`jest.resetModules()`).\n\n`useModule(module)` imports module before each test.\n\n```js\nimport { useResetModules, useTestState } from \"jest-hooks\";\n\nuseResetModules();\nconst m = useModule(\"module-with-global-state\");\n\nit(\"should modify global state\", () =\u003e {\n  m.set(1);\n  expect(m.get()).toBe(1);\n});\n\nit(\"should reload module\", () =\u003e {\n  expect(m.get()).toBe(0);\n});\n```\n\n### Timers\n\n`useTimers()` mocks timers `jest.useFakeTimers()` before each test and resets them after each test\n`jest.useRealTimers()`.\n\n```js\nimport { useTimers } from \"jest-hooks\";\n\nconst timers = useTimers();\n\ndescribe(\"timers\", () =\u003e {\n  it(\"should advance time\", () =\u003e {\n    let triggered = 0;\n    setTimeout(() =\u003e { triggered++; }, 1000);\n    setTimeout(() =\u003e { triggered++; }, 2000);\n    timers.advance(1500);\n    expect(triggered).toBe(1);\n  });\n});\n```\n\n### Mock\n\n`useMockFn(implementation)` creates a mock function (`jest.fn()`) and resets it after each test.\n\n```js\nimport { useResetModules, useModule, useMockFn } from \"jest-hooks\";\n\nuseResetModules();\nconst video = useModule(\"video\");\nconst play = useMockFn(() =\u003e video.play);\n\ndescribe(\"function\", () =\u003e {\n  it(\"should mock function\", () =\u003e {\n    play();\n    expect(play).toHaveBeenCalled();\n  });\n\n  it(\"should reset mocked function\", () =\u003e {\n    expect(play).not.toHaveBeenCalled();\n  });\n});\n```\n\n`useSpyOn(object, method, accessType)` creates a spy object (`jest.spyOn()`) and resets it after each test.\n\n\n```js\nimport { useResetModules, useModule, useSpyOn } from \"jest-hooks\";\n\nuseResetModules();\nconst video = useModule(\"video\");\nconst spy = useSpyOn(() =\u003e video, \"play\");\n\ndescribe(\"spy\", () =\u003e {\n  it(\"should spy on a method\", () =\u003e {\n    video.play();\n    expect(spy).toHaveBeenCalled();\n  });\n\n  it(\"should reset spy instance\", () =\u003e {\n    expect(spy).not.toHaveBeenCalled();\n  });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalvoid%2Fjest-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocalvoid%2Fjest-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalvoid%2Fjest-hooks/lists"}