{"id":15315839,"url":"https://github.com/wobsoriano/vue-test-composables","last_synced_at":"2025-04-15T02:19:27.872Z","repository":{"id":40586712,"uuid":"468633410","full_name":"wobsoriano/vue-test-composables","owner":"wobsoriano","description":"Test composables in Vue 2 and 3.","archived":false,"fork":false,"pushed_at":"2023-01-02T10:23:46.000Z","size":193,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T02:19:24.516Z","etag":null,"topics":["testing","vue"],"latest_commit_sha":null,"homepage":"","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/wobsoriano.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":"2022-03-11T06:20:52.000Z","updated_at":"2022-08-21T16:26:03.000Z","dependencies_parsed_at":"2023-02-01T02:30:59.794Z","dependency_job_id":null,"html_url":"https://github.com/wobsoriano/vue-test-composables","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/wobsoriano%2Fvue-test-composables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wobsoriano%2Fvue-test-composables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wobsoriano%2Fvue-test-composables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wobsoriano%2Fvue-test-composables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wobsoriano","download_url":"https://codeload.github.com/wobsoriano/vue-test-composables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991558,"owners_count":21194894,"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":["testing","vue"],"created_at":"2024-10-01T08:52:29.127Z","updated_at":"2025-04-15T02:19:27.843Z","avatar_url":"https://github.com/wobsoriano.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vue-test-composables\n\n[![Build Size](https://img.shields.io/bundlephobia/minzip/vue-test-composables?label=bundle%20size\u0026style=flat\u0026colorA=000000\u0026colorB=000000)](https://bundlephobia.com/result?p=vue-test-composables)\n[![Version](https://img.shields.io/npm/v/vue-test-composables?style=flat\u0026colorA=000000\u0026colorB=000000)](https://www.npmjs.com/package/vue-test-composables)\n\nTest composables in Vue 2 and 3.\n\n## Installation:\n\n```bash\npnpm add vue-test-composables -D\n```\n\nIf your app is using Vue 2, you also need to install the composition api: `@vue/composition-api`.\n\n### Basic usage\n\nA simple counter composable:\n\n```ts\nimport { ref } from 'vue'\n\nexport function useCounter() {\n  const count = ref(0)\n\n  function increment() {\n    count.value++\n  }\n\n  return {\n    count,\n    increment,\n  }\n}\n```\n\nTo test, render it using the `renderComposable` function provided by the library:\n\n```ts\nimport { renderComposable } from 'vue-test-composables'\nimport { useCounter } from './counter'\n\ntest('should increment count', () =\u003e {\n  const { result } = renderComposable(() =\u003e useCounter())\n\n  expect(result.count.value).toBe(0)\n  result.increment()\n  expect(result.count.value).toBe(1)\n})\n```\n\nYou can unmount the underlying component by using unmount helper returned by mount to trigger onUnmounted and related lifecycle hooks:\n\n```ts\nconst { result, unmount } = renderComposable(() =\u003e useCounter())\n\n// Unmount underlying comonent to trigger lifecycle hooks\nunmount()\n```\n\n### Provide/Inject\n\nExample using [vue-query](https://github.com/DamianOsipiuk/vue-query)\n\n```ts\nimport { useQuery, useQueryProvider } from 'vue-query'\nimport { renderComposable } from 'vue-test-composables'\n\nfunction useUser() {\n  return useQuery('user', () =\u003e\n    fetch('/api/user').then(\n      res =\u003e res.json,\n    ),\n  )\n}\n\ntest('useUser', async() =\u003e {\n  const { result, waitFor } = renderComposable(() =\u003e useUser(), {\n    provider() {\n      useQueryProvider()\n    },\n  })\n\n  await waitFor(() =\u003e result.isSuccess.value)\n\n  await expect(result.data.value).resolves.toMatchObject({\n    id: 1,\n    username: 'johndoe',\n    email: 'johndoe@mail.com',\n  })\n})\n```\n\n## Credits\n\nThis is a fork of [vue-composable-tester](https://github.com/ktsn/vue-composable-tester) with some modifications using [vue-demi](https://github.com/vueuse/vue-demi/).\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwobsoriano%2Fvue-test-composables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwobsoriano%2Fvue-test-composables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwobsoriano%2Fvue-test-composables/lists"}