{"id":16875944,"url":"https://github.com/evelynhathaway/context-thief","last_synced_at":"2026-05-11T03:48:27.961Z","repository":{"id":38173689,"uuid":"318904329","full_name":"evelynhathaway/context-thief","owner":"evelynhathaway","description":"⚛🦹‍♀️ Helper function to steal React context values for testing","archived":false,"fork":false,"pushed_at":"2022-08-21T19:23:56.000Z","size":1346,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T01:04:38.499Z","etag":null,"topics":["context","enzyme","nodejs","react","testing","testing-library"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/context-thief","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/evelynhathaway.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-12-05T22:44:23.000Z","updated_at":"2023-03-04T04:13:33.000Z","dependencies_parsed_at":"2022-09-02T10:52:04.934Z","dependency_job_id":null,"html_url":"https://github.com/evelynhathaway/context-thief","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evelynhathaway%2Fcontext-thief","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evelynhathaway%2Fcontext-thief/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evelynhathaway%2Fcontext-thief/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evelynhathaway%2Fcontext-thief/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evelynhathaway","download_url":"https://codeload.github.com/evelynhathaway/context-thief/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244327372,"owners_count":20435398,"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":["context","enzyme","nodejs","react","testing","testing-library"],"created_at":"2024-10-13T15:37:38.577Z","updated_at":"2026-05-11T03:48:22.889Z","avatar_url":"https://github.com/evelynhathaway.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cimg alt=\"Context Thief icon\" width=\"128\" height=\"128\" align=\"center\" src=\".github/icon.png\"/\u003e\n\n# Context Thief\n\n**Helper function to steal React context values for testing**\n\n[![npm version](https://badgen.net/npm/v/context-thief?icon=npm)](https://www.npmjs.com/package/context-thief)\n[![check status](https://badgen.net/github/checks/evelynhathaway/context-thief/main?icon=github)](https://github.com/evelynhathaway/context-thief/actions)\n[![license: MIT](https://badgen.net/badge/license/MIT/blue)](/LICENSE)\n\n\u003c/div\u003e\n\n## Description\n\nContext Thief stores the current context value for the inputted context for use in tests.\n\nIf you test components with contexts and don't want to create a new function or component every time, this module is for you!\n\n## Installation\n\n```bash\nnpm install --save-dev context-thief\n```\n\n## Usage\n\n### `createContextThief(context)`\n\n**Returns**: `{ContextThief, contextValue}` Object containing the component to render and the outputted value\n\n| Parameter | Type      | Description                            |\n| --------- | --------- | -------------------------------------- |\n| context   | `Context` | Instance of `React.Context` to consume |\n\n## Example\n\n**`example-component.tsx`**\n\n```tsx\nimport React from \"react\";\n\nexport const ExampleContext = React.createContext(false);\nexport const ExampleComponent: React.FC\u003c{children: React.ReactNode}\u003e = ({children}) =\u003e {\n    return (\n        \u003cTestContext.Provider value={true}\u003e\n            {children}\n        \u003c/TestContext.Provider\u003e\n    );\n};\n```\n\n**`example-component.test.tsx`**\n\n```tsx\nimport React from \"react\";\nimport {render} from \"@testing-library/react\";\nimport {createContextThief} from \"context-thief\";\nimport {ExampleContext, ExampleComponent} from \"./example-component\";\n\nit(\"should have the default current context value\", () =\u003e {\n    const {ContextThief, contextValue} = createContextThief(ExampleContext);\n\n    render(\n        \u003cExampleComponent\u003e\n            \u003cContextThief /\u003e\n        \u003c/ExampleComponent\u003e\n    );\n\n    expect(contextValue.current).toBe(true);\n});\n```\n\n## License\n\nCopyright Evelyn Hathaway, [MIT License](/LICENSE)\n\n### Icon Glyph\n\nIcon glyph made by [Gregor Cresnar](https://thenounproject.com/grega.cresnar/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevelynhathaway%2Fcontext-thief","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevelynhathaway%2Fcontext-thief","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevelynhathaway%2Fcontext-thief/lists"}