{"id":17921857,"url":"https://github.com/zth/enzyme-async-helpers","last_synced_at":"2025-03-24T02:32:03.681Z","repository":{"id":57226101,"uuid":"114035095","full_name":"zth/enzyme-async-helpers","owner":"zth","description":"Async helpers for testing React components with Enzyme.","archived":false,"fork":false,"pushed_at":"2018-02-22T18:38:35.000Z","size":58,"stargazers_count":16,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-10T09:13:20.864Z","etag":null,"topics":["async","async-await","enzyme","enzyme-testing","javascript","react","tdd","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zth.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-12-12T20:18:30.000Z","updated_at":"2020-04-22T18:14:11.000Z","dependencies_parsed_at":"2022-08-24T10:40:15.122Z","dependency_job_id":null,"html_url":"https://github.com/zth/enzyme-async-helpers","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/zth%2Fenzyme-async-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fenzyme-async-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fenzyme-async-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zth%2Fenzyme-async-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zth","download_url":"https://codeload.github.com/zth/enzyme-async-helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221931696,"owners_count":16903799,"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":["async","async-await","enzyme","enzyme-testing","javascript","react","tdd","testing"],"created_at":"2024-10-28T20:36:27.763Z","updated_at":"2024-10-28T20:36:28.188Z","avatar_url":"https://github.com/zth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# enzyme-async-helpers\nA library to aid in testing async React components and methods using Enzyme.\n\n## Installation\nThis library was built with React 16 and Enzyme 3 in mind. It *might* work on lower versions\nas well, but the lib is developed for and tested on those versions.\n```\nyarn add --dev enzyme-async-helpers\n```\n\n## Usage\nI recommend checking out the tests to see more examples than the ones below. \nThe lib exposes the following methods:\n\n### waitForElement\n*Signature*: `(wrapper: EnzymeWrapper, elementSelector: EnzymeSelector, config?: Config) =\u003e Promise\u003cvoid\u003e`\n\nWait for an element to appear. You can use any valid Enzyme selector (a component, CSS selector, etc). \n\n```javascript\nimport { waitForElement } from 'enzyme-async-helpers';\n...\n\nit('should wait for MyComponent to appear', async () =\u003e {\n    const wrapper = mount(\u003cWrapper /\u003e);\n    \n    await waitForElement(wrapper, MyComponent);\n    expect(wrapper.find(MyComponent).length).toBe(1);\n});\n``` \n\n### waitForState\n*Signature*: `(wrapper: EnzymeWrapper, stateValidationFn: (state: Object) =\u003e boolean, config?: Config) =\u003e Promise\u003cvoid\u003e`\n\nWait for your component's state to update to something.\n\n```javascript\nimport { waitForState } from 'enzyme-async-helpers';\n...\n\nit('should wait for loading to stop', async () =\u003e {\n    const wrapper = mount(\u003cMyComponent /\u003e);\n    \n    await waitForState(wrapper, state =\u003e state.loading === false);\n    expect(wrapper.instance().state.loading).toBe(false);\n});\n```\n\n### waitForProps\n*Signature*: `(wrapper: EnzymeWrapper, propsValidationFn: (props: Object) =\u003e boolean, config?: Config) =\u003e Promise\u003cvoid\u003e`\n\nWait for your component's props to update to something.\n\n```javascript\nimport { waitForProps } from 'enzyme-async-helpers';\n...\n\nit('should wait for someProp to be valid', async () =\u003e {\n    const wrapper = mount(\u003cWrapper /\u003e); // Wrapper renders SomeComponent and passes in props\n    const componentWrapper = wrapper.find(SomeComponent);\n    \n    await waitForProps(componentWrapper, props =\u003e props.someProp === 'test');\n    expect(componentWrapper.instance().props.someProp).toBe('test');\n});\n```  \n\n### config\nAll the methods listed above take a third `config` argument of the following shape:\n```javascript\ntype Config = {\n    interval: number, // Default: 50, how often to check for validity\n    timeout: number, // Default: 2000 (2 seconds), how long to wait before timing out\n    logStructureOnTimeout?: boolean, // Default: true, logs the wrapper's rendered structure when the wait times out. An attempt to help out in finding what's wrong.\n    logStructureOnSuccess?: boolean // Default: false, logs the wrapper's rendered structure on success.\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzth%2Fenzyme-async-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzth%2Fenzyme-async-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzth%2Fenzyme-async-helpers/lists"}