{"id":13624572,"url":"https://github.com/devlato/async-wait-until","last_synced_at":"2025-04-05T13:08:21.945Z","repository":{"id":42666059,"uuid":"80735243","full_name":"devlato/async-wait-until","owner":"devlato","description":"Waits for an expectation to be truthy. A small library with a convenient API suitable for unit and integration testing","archived":false,"fork":false,"pushed_at":"2024-04-13T11:04:22.000Z","size":577,"stargazers_count":72,"open_issues_count":22,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T07:01:09.810Z","etag":null,"topics":["async","await","integration-testing","javascript","jsdom","node","nodejs","npm","predicate","promise","react-testing-library","sync","testing","timer","typescript","unit-testing","wait"],"latest_commit_sha":null,"homepage":"https://devlato.github.io/async-wait-until/","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/devlato.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"devlato","custom":"http://paypal.me/devlatoau"}},"created_at":"2017-02-02T14:53:21.000Z","updated_at":"2024-06-12T07:22:52.505Z","dependencies_parsed_at":"2023-09-23T11:18:48.516Z","dependency_job_id":"d64e4137-9be3-4285-a350-fe3938eb4977","html_url":"https://github.com/devlato/async-wait-until","commit_stats":{"total_commits":70,"total_committers":6,"mean_commits":"11.666666666666666","dds":0.3285714285714286,"last_synced_commit":"83482cc3d27a900560488ce5d16afdbda85734f0"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlato%2Fasync-wait-until","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlato%2Fasync-wait-until/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlato%2Fasync-wait-until/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlato%2Fasync-wait-until/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devlato","download_url":"https://codeload.github.com/devlato/async-wait-until/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247179288,"owners_count":20897010,"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","await","integration-testing","javascript","jsdom","node","nodejs","npm","predicate","promise","react-testing-library","sync","testing","timer","typescript","unit-testing","wait"],"created_at":"2024-08-01T21:01:43.869Z","updated_at":"2025-04-05T13:08:21.940Z","avatar_url":"https://github.com/devlato.png","language":"TypeScript","readme":"# async-wait-until\n\nA lightweight, zero-dependency library for waiting asynchronously until a specific condition is met. Works in any JavaScript environment that supports [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), including older Node.js versions and browsers (with polyfills if necessary).\n\n![npm version](https://img.shields.io/npm/v/async-wait-until)\n[![npm downloads](https://img.shields.io/npm/dw/async-wait-until)](https://npmjs.org/package/async-wait-until)\n![MIT License](https://img.shields.io/npm/l/async-wait-until)\n[![Maintainability](https://api.codeclimate.com/v1/badges/2a967399786c0d306247/maintainability)](https://codeclimate.com/github/devlato/async-wait-until/maintainability)\n\n## 📖 Detailed Documentation\n\nFor detailed documentation, visit [https://devlato.github.io/async-wait-until/](https://devlato.github.io/async-wait-until/)\n\n---\n\n## 🚀 Installation\n\nInstall using npm:\n\n```sh\nnpm install async-wait-until\n```\n\nThe library includes UMD, CommonJS, and ESM bundles, so you can use it in any environment.\n\n```javascript\nimport { waitUntil } from 'async-wait-until';\n\n// Example: Wait for an element to appear\nawait waitUntil(() =\u003e document.querySelector('#target') !== null);\n```\n\n---\n\n## 🛠️ How to Use\n\n### Basic Example: Wait for a DOM Element\n\n```javascript\nimport { waitUntil } from 'async-wait-until';\n\nconst waitForElement = async () =\u003e {\n  // Wait for an element with the ID \"target\" to appear\n  const element = await waitUntil(() =\u003e document.querySelector('#target'), { timeout: 5000 });\n  console.log('Element found:', element);\n};\n\nwaitForElement();\n```\n\n### Handling Timeouts\n\nIf the condition is not met within the timeout, a `TimeoutError` is thrown.\n\n```javascript\nimport { waitUntil, TimeoutError } from 'async-wait-until';\n\nconst waitForElement = async () =\u003e {\n  try {\n    const element = await waitUntil(() =\u003e document.querySelector('#target'), { timeout: 5000 });\n    console.log('Element found:', element);\n  } catch (error) {\n    if (error instanceof TimeoutError) {\n      console.error('Timeout: Element not found');\n    } else {\n      console.error('Unexpected error:', error);\n    }\n  }\n};\n\nwaitForElement();\n```\n\n---\n\n## 📚 API\n\n### `waitUntil(predicate, options)`\n\nWaits for the `predicate` function to return a truthy value and resolves with that value.\n\n**Parameters:**\n\n| Name                              | Type       | Required | Default   | Description                                                                          |\n| --------------------------------- | ---------- | -------- | --------- | ------------------------------------------------------------------------------------ |\n| `predicate`                       | `Function` | ✅ Yes   | -         | A function that returns a truthy value (or a Promise for one).                       |\n| `options.timeout`                 | `number`   | 🚫 No    | `5000` ms | Maximum wait time before throwing `TimeoutError`. Use `WAIT_FOREVER` for no timeout. |\n| `options.intervalBetweenAttempts` | `number`   | 🚫 No    | `50` ms   | Interval between predicate evaluations.                                              |\n\n---\n\n## 💡 Recipes\n\n### Wait Indefinitely\n\nUse `WAIT_FOREVER` to wait without a timeout:\n\n```javascript\nimport { waitUntil, WAIT_FOREVER } from 'async-wait-until';\n\nawait waitUntil(() =\u003e someCondition, { timeout: WAIT_FOREVER });\n```\n\n### Adjust Retry Interval\n\nChange how often the predicate is evaluated:\n\n```javascript\nawait waitUntil(() =\u003e someCondition, { intervalBetweenAttempts: 1000 }); // Check every 1 second\n```\n\n---\n\n## 🧪 Development and Testing\n\nContributions are welcome! To contribute:\n\n1. Fork and clone the repository.\n2. Install dependencies: `npm install`.\n3. Use the following commands:\n\n- **Run Tests:** `npm test`\n- **Lint Code:** `npm run lint`\n- **Format Code:** `npm run format`\n- **Build Library:** `npm run build`\n- **Generate Docs:** `npm run docs`\n\n---\n\n## 📝 Links\n\n- [License](./LICENSE)\n- [Detailed Documentation](https://devlato.github.io/async-wait-until/)\n- [Changelog](./CHANGELOG.md) - Track version updates and changes\n- [Contributing Guidelines](./CONTRIBUTING.md) - How to contribute to the project\n- [Code of Conduct](./CODE_OF_CONDUCT.md) - Community standards and expectations\n","funding_links":["https://github.com/sponsors/devlato","http://paypal.me/devlatoau"],"categories":["javascript","typescript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlato%2Fasync-wait-until","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevlato%2Fasync-wait-until","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlato%2Fasync-wait-until/lists"}