{"id":13701383,"url":"https://github.com/phanan/vue-test-helpers","last_synced_at":"2025-07-06T04:39:55.609Z","repository":{"id":72022047,"uuid":"118028649","full_name":"phanan/vue-test-helpers","owner":"phanan","description":"Some helpers for vue-test-utils","archived":false,"fork":false,"pushed_at":"2020-02-12T18:34:35.000Z","size":106,"stargazers_count":29,"open_issues_count":4,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T07:32:36.461Z","etag":null,"topics":["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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phanan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2018-01-18T19:33:43.000Z","updated_at":"2023-11-25T05:15:37.000Z","dependencies_parsed_at":"2023-02-28T06:32:36.371Z","dependency_job_id":null,"html_url":"https://github.com/phanan/vue-test-helpers","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanan%2Fvue-test-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanan%2Fvue-test-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanan%2Fvue-test-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanan%2Fvue-test-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phanan","download_url":"https://codeload.github.com/phanan/vue-test-helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244902929,"owners_count":20529114,"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-08-02T20:01:34.482Z","updated_at":"2025-03-22T03:31:21.746Z","avatar_url":"https://github.com/phanan.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# vue-test-helpers [![Build Status](https://travis-ci.org/phanan/vue-test-helpers.svg?branch=master)](https://travis-ci.org/phanan/vue-test-helpers)\n\nHelpers and syntactic sugars on top of [vue-test-utils](https://github.com/vuejs/vue-test-utils).\n\n## Install\n\nFirst install the package with yarn or npm:\n\n```bash\n$ yarn add vue-test-helpers --dev\n```\n\nAlso you'll need a peer dependency of `vue-test-utils`. Install it with:\n\n```bash\n$ yarn add @vue/test-utils --dev\n```\n\nThen, before your tests (for example in a setup script), import and call the function:\n\n```js\nimport setupHelpers from 'vue-test-helpers'\n\nsetupHelpers()\n```\n\nThis will do two things:\n\n1. By default, make [`mount`](https://vue-test-utils.vuejs.org/api/#mount) and [`shallowMount`](https://vue-test-utils.vuejs.org/api/#shallowmount) (also aliased as `shallow`) available globally, so you don't need to manually `import { mount, shallowMount } from '@vue/test-utils'` at the beginning of every test file. If this behavior is not what you want, just call `setupHelpers({ registerGlobals: false })` instead.\n2. Add some helpers and syntactic sugars on top of `Wrapper` to create your test a better experience. See the next section for details.\n\n## Available helpers\n\n\u003e These helpers are available on `Wrapper` instances only, since I'm not a fan of `WrapperArray` which is just a very thin wrapper around an array of `Wrapper`'s. If you are dealing with a `WrapperArray`, just iterate through its `.wrappers` collection and run the helpers on each item.\n\n* **`.has(selector)`**: alias for [`.contains(selector)`](https://vue-test-utils.vuejs.org/api/wrapper-array/contains.html)\n```js\nexpect(wrapper.has('p')).toBe(true)\nexpect(wrapper.has('#foo')).toBe(true)\nexpect(wrapper.has(childComponent)).toBe(false)\n```\n* **`.hasAll|containsAll(...selectors)`**: asserts that the wrapper has all provided selectors\n```js\nexpect(wrapper.hasAll('p', '#foo', childComponent)).toBe(false)\n```\n* **`.hasAny|containsAny(...selectors)`**: asserts that the wrapper has any of the provided selectors\n```js\nexpect(wrapper.hasAny('p', '#foo', childComponent)).toBe(true)\n```\n* **`.hasNone|containsNone(...selectors)`**: asserts that the wrapper has none of the provided selectors\n```js\nexpect(wrapper.hasNone('p', '#foo', childComponent)).toBe(false)\n```\n* **`.hasClass|hasClasses(...classes)`**: asserts that the wrapper has the CSS class(es).\n```js\nexpect(wrapper.find('.foo').hasClass('foo')).toBe(true)\nexpect(wrapper.find('.foo.bar').hasClasses('foo', 'bar')).toBe(true)\n```\n* **`.hasAttribute(name, value)`**: asserts that the wrapper has an attribute `name` with the value `value`\n```js\nexpect(wrapper.find('[foo=\"bar\"]').hasAttribute('foo', 'bar')).toBe(true)\n```\n* **`.hasProp(name, value)`**: asserts that the wrapper has a prop `name` with the value `value`\n```js\nexpect(wrapper.hasProp('foo', 'bar')).toBe(true)\n```\n\u003e Note: `hasClass`, `hasAttribute`, and `hasProp` are actually available in `vue-test-utils`, but marked as deprecated and will be removed in 1.0.\n* **`.hasEmitted(name[, value])`**: asserts that an event `name` has been emitted, optionally with a value `value`\n```js\nwrapper.vm.$emit('foo', 'bar')\nexpect(wrapper.hasEmitted('foo')).toBe(true)\nexpect(wrapper.hasEmitted('foo', 'bar')).toBe(true)\n```\n* **`.id()`**: gets the id of the contained element\n```js\nexpect(wrapper.find('#foo').id()).toBe('foo')\n```\n* **`.click|dblclick|input|submit|focus|blur|change([options])`**: triggers the click/dblclick/input/submit/focus/blur/change event on the contained element, optionally with an [`options`](https://vue-test-utils.vuejs.org/guides/#testing-key-mouse-and-other-dom-events) object. These methods return the wrapper instance, useful for chaining.\n```js\nexpect(wrapper.click().hasEmitted('clicked')).toBe(true)\nexpect(wrapper.click({ button: 1 }).hasEmitted('rightClicked')).toBe(true)\n```\n* **`.click|dblclick|input|submit|focus|blur|change(selector[, options])`**: finds the contained element by `selector` and triggers the click/dblclick/input/submit/focus/blur/change event on it, optionally with an [`options`](https://vue-test-utils.vuejs.org/guides/#testing-key-mouse-and-other-dom-events) object. These methods return the wrapper instance, useful for chaining.\n```js\nexpect(wrapper.click('button').hasEmitted('buttonClicked')).toBe(true)\nexpect(wrapper.click('button', { ctrlKey: true }).hasEmitted('buttonCtrlClicked')).toBe(true)\n```\n* **`.setValue(value)`**: sets the value of the contained (input) element. This method returns the called instance, useful for chaining.\n```js\nwrapper.find('input').setValue('foo').change()\n```\n* **`.getValue()`**: gets the value of the contained (input) element\n```js\nexpect(wrapper.find('input').setValue('foo').getValue()).toBe('foo')\n```\n* **`.value`**: a proxy for the value of the contained (input) element\n```js\nwrapper.find('input').value = 'foo'\nexpect(wrapper.find('input').value).toBe('foo')\n```\n\n## License\n\nMIT © [Phan An](https://phanan.net)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphanan%2Fvue-test-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphanan%2Fvue-test-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphanan%2Fvue-test-helpers/lists"}