{"id":22098603,"url":"https://github.com/ariesjia/vue-composition-test-utils","last_synced_at":"2025-07-24T22:33:40.279Z","repository":{"id":52849757,"uuid":"305143768","full_name":"ariesjia/vue-composition-test-utils","owner":"ariesjia","description":"Simple vue composition api unit test utilities support both Vue 2 and 3","archived":false,"fork":false,"pushed_at":"2024-02-22T03:34:15.000Z","size":242,"stargazers_count":37,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-28T14:56:47.828Z","etag":null,"topics":["composition-api","unit-testing","vue"],"latest_commit_sha":null,"homepage":"","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/ariesjia.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-18T16:18:33.000Z","updated_at":"2024-05-28T19:12:35.000Z","dependencies_parsed_at":"2024-06-19T10:00:26.196Z","dependency_job_id":"27552031-9e7b-4df6-8c5c-68e778277a3e","html_url":"https://github.com/ariesjia/vue-composition-test-utils","commit_stats":{"total_commits":16,"total_committers":2,"mean_commits":8.0,"dds":0.0625,"last_synced_commit":"21fb1244b7c18c63895a4c3bf7b1a12019f48111"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariesjia%2Fvue-composition-test-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariesjia%2Fvue-composition-test-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariesjia%2Fvue-composition-test-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariesjia%2Fvue-composition-test-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ariesjia","download_url":"https://codeload.github.com/ariesjia/vue-composition-test-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227482912,"owners_count":17780070,"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":["composition-api","unit-testing","vue"],"created_at":"2024-12-01T04:21:00.691Z","updated_at":"2024-12-01T04:21:01.507Z","avatar_url":"https://github.com/ariesjia.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# vue-composition-test-utils\nSimple vue composition api testing utilities\n\n[![Actions Status](https://github.com/ariesjia/vue-composition-test-utils/workflows/Node%20CI/badge.svg)](https://github.com/ariesjia/vue-composition-test-utils/actions)\n[![NPM](https://img.shields.io/npm/v/vue-composition-test-utils.svg)](https://www.npmjs.com/package/vue-composition-test-utils)\n[![license](https://badgen.net/badge/license/MIT/blue)](https://github.com/ariesjia/vue-composition-test-utils/blob/master/LICENSE)\n\n\n## Install\n```bash\n// use yarn\nyarn add vue-composition-test-utils -D\n// use npm\nnpm install vue-composition-test-utils -D\n```\n\n## Demo\n\n#### Code\n\n```js\nimport { ref } from 'vue'\n\nexport function useCounter(initialValue = 0) {\n  const count = ref(initialValue)\n  const inc = (delta = 1) =\u003e (count.value += delta)\n  return { count, inc }\n}\n```\n\n#### Test\n\n```js\nimport { mountComposition, nextTick } from 'vue-composition-test-utils'\n\ntest('should get current composition result', function() {\n  const wrapper = mountComposition(useCounter)\n  expect(wrapper.result.current.count.value).toEqual(0)\n});\n\ntest('should render template though template option', async function() {\n  const wrapper = mountComposition(useCounter, {\n    component: {\n      template: 'hello world {{result.current.count.value}}',\n    }\n  })\n  expect(wrapper.html()).toEqual('hello world 0')\n  await nextTick(() =\u003e {\n    wrapper.result.current.inc()\n  })\n  expect(wrapper.result.current.count.value).toEqual(1)\n  expect(wrapper.html()).toEqual('hello world 1')\n});\n\n```\n\n\n#### vue2 + @vue/composition-api demo\n[https://github.com/ariesjia/vue-composition-test-utils/blob/master/packages/test-vue2/test/simple.test.js](https://github.com/ariesjia/vue-composition-test-utils/blob/master/packages/test-vue2/test/simple.test.js)\n\n\n#### vue3 demo\n[https://github.com/ariesjia/vue-composition-test-utils/blob/master/packages/test-vue3/test/simple.test.js](https://github.com/ariesjia/vue-composition-test-utils/blob/master/packages/test-vue3/test/simple.test.js)\n\n## API\n\n```typescript\nimport {GlobalMountOptions} from \"@vue/test-utils/dist/types\";\nimport {ComponentOptionsWithoutProps} from \"vue\";\n\ninterface MountingOptions\u003cProps, Data = {}\u003e {\n    data?: () =\u003e {} extends Data ? any : Data extends object ? Partial\u003cData\u003e : any;\n    props?: Props;\n    attrs?: Record\u003cstring, unknown\u003e;\n    slots?: SlotDictionary \u0026 {\n        default?: Slot;\n    };\n    global?: GlobalMountOptions;\n    attachTo?: HTMLElement | string;\n    shallow?: boolean;\n    component?: ComponentOptionsWithoutProps;\n}\n\ninterface MountingResult\u003cR\u003e {\n    current: R | null;\n    error: Error | null;\n}\n\nexport declare const mountComposition: \u003cR, Props\u003e(callback: () =\u003e R, options?: MountingOptions\u003cnever\u003e) =\u003e import(\"@vue/test-utils\").VueWrapper\u003cimport(\"vue\").ComponentPublicInstance\u003cProps, {}, {}, {}, {}, Record\u003cstring, any\u003e, import(\"vue\").VNodeProps \u0026 Props, {}, false, import(\"vue\").ComponentOptionsBase\u003cany, any, any, any, any, any, any, any, any, {}\u003e\u003e\u003e \u0026 {\n    result: MountingResult\u003cR\u003e;\n};\n\nexport const nextTick: (fn?: () =\u003e void) =\u003e Promise\u003cvoid\u003e\n```\n\n\n### Thanks\n\nThis project is inspired by [vue-demi](https://github.com/antfu/vue-demi)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariesjia%2Fvue-composition-test-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fariesjia%2Fvue-composition-test-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariesjia%2Fvue-composition-test-utils/lists"}