├── .eslintrc.json ├── .gitignore ├── .travis.yml ├── renovate.json ├── src ├── fixtures │ ├── index.js │ ├── Component.vue │ └── Wrapper.js ├── index.js ├── utils.js └── createWrapperHelpers.js ├── test ├── components │ ├── Inputs.vue │ ├── Contains.vue │ ├── Props.vue │ ├── Basic.vue │ └── Events.vue ├── setup.js └── helpers.spec.js ├── .editorconfig ├── webpack.config.js ├── package.json ├── README.md └── dist └── vue-test-helpers.min.js /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "standard" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.swp 3 | .DS_Store 4 | *.log 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '8' 4 | - '6' 5 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /src/fixtures/index.js: -------------------------------------------------------------------------------- 1 | import Wrapper from './Wrapper' 2 | 3 | export { Wrapper } 4 | -------------------------------------------------------------------------------- /src/fixtures/Component.vue: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /test/components/Inputs.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /test/components/Contains.vue: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /test/components/Props.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | -------------------------------------------------------------------------------- /test/components/Basic.vue: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | indent_size = 2 10 | -------------------------------------------------------------------------------- /test/setup.js: -------------------------------------------------------------------------------- 1 | require('jsdom-global')() 2 | require('babel-polyfill') 3 | require('chai').should() 4 | require('vue').productionTip = false 5 | 6 | global.expect = require('expect') 7 | global.sinon = require('sinon') 8 | -------------------------------------------------------------------------------- /src/fixtures/Wrapper.js: -------------------------------------------------------------------------------- 1 | import { shallowMount } from '@vue/test-utils' 2 | import Component from './Component.vue' 3 | 4 | // A workaround because at the time being vue-test-util doesn't export `Wrapper`. 5 | export default shallowMount(Component).find('.foo').constructor 6 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import { shallowMount, mount } from '@vue/test-utils' 2 | import createWrapperHelpers from './createWrapperHelpers' 3 | 4 | export default function (options = { registerGlobals: true }) { 5 | if (options.registerGlobals) { 6 | global.shallow = global.shallowMount = shallowMount 7 | global.mount = mount 8 | } 9 | 10 | createWrapperHelpers() 11 | } 12 | -------------------------------------------------------------------------------- /test/components/Events.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 22 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const JsMinify = require('babel-minify-webpack-plugin') 3 | 4 | module.exports = { 5 | entry: './src/index.js', 6 | output: { 7 | path: path.resolve(__dirname, 'dist'), 8 | filename: 'vue-test-helpers.min.js', 9 | libraryTarget: 'commonjs-module' 10 | }, 11 | module: { 12 | rules: [ 13 | { 14 | test: /\.vue$/, 15 | loader: 'vue-loader' 16 | }, 17 | { 18 | test: /\.js$/, 19 | loader: 'babel-loader', 20 | exclude: /node_modules/ 21 | } 22 | ] 23 | }, 24 | externals: { 25 | '@vue/test-utils': 'commonjs @vue/test-utils' 26 | }, 27 | plugins: [ 28 | new JsMinify() 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-test-helpers", 3 | "version": "2.0.0", 4 | "description": "Helpers for vue-test-utils", 5 | "repository": "phanan/vue-test-helpers", 6 | "main": "dist/vue-test-helpers.min.js", 7 | "scripts": { 8 | "lint": "eslint src", 9 | "test": "yarn lint && mocha-webpack --webpack-config webpack.config.js --require test/setup.js test/**/*.spec.js", 10 | "build": "NODE_ENV=production && BABEL_ENV=production && webpack" 11 | }, 12 | "keywords": [ 13 | "vue", 14 | "test", 15 | "testing", 16 | "unit test", 17 | "helpers" 18 | ], 19 | "author": { 20 | "name": "Phan An", 21 | "email": "me@phanan.net", 22 | "url": "https://phanan.net" 23 | }, 24 | "license": "MIT", 25 | "babel": { 26 | "presets": [ 27 | "env", 28 | "minify" 29 | ], 30 | "plugins": [ 31 | "add-module-exports" 32 | ] 33 | }, 34 | "peerDependencies": { 35 | "@vue/test-utils": "^1.0.0-beta.20" 36 | }, 37 | "devDependencies": { 38 | "@vue/test-utils": "^1.0.0-beta.20", 39 | "babel-cli": "^6.26.0", 40 | "babel-core": "^6.26.0", 41 | "babel-eslint": "^8.2.1", 42 | "babel-loader": "^7.1.2", 43 | "babel-minify": "^0.2.0", 44 | "babel-minify-webpack-plugin": "^0.2.0", 45 | "babel-plugin-add-module-exports": "^0.2.1", 46 | "babel-polyfill": "^6.26.0", 47 | "babel-preset-env": "^1.6.1", 48 | "babel-preset-minify": "^0.2.0", 49 | "chai": "^4.1.2", 50 | "css-loader": "^0.28.8", 51 | "deep-equal": "^1.0.1", 52 | "eslint": "^4.15.0", 53 | "eslint-config-standard": "^11.0.0-beta.0", 54 | "eslint-plugin-import": "^2.8.0", 55 | "eslint-plugin-node": "^5.2.1", 56 | "eslint-plugin-promise": "^3.6.0", 57 | "eslint-plugin-standard": "^3.0.1", 58 | "expect": "^22.1.0", 59 | "jsdom": "^11.5.1", 60 | "jsdom-global": "^3.0.2", 61 | "mocha": "^4.1.0", 62 | "mocha-webpack": "^1.0.1", 63 | "sinon": "^4.1.6", 64 | "sinon-chai": "^2.14.0", 65 | "vue": "^2.5.13", 66 | "vue-loader": "^13.7.0", 67 | "vue-template-compiler": "^2.5.13", 68 | "webpack": "^3.10.0" 69 | }, 70 | "dependencies": { 71 | "np": "^2.18.3" 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/utils.js: -------------------------------------------------------------------------------- 1 | export function throwError (msg) { 2 | throw new Error(`[vue-test-helpers]: ${msg}`) 3 | } 4 | 5 | export function isDomSelector (selector) { 6 | if (typeof selector !== 'string') { 7 | return false 8 | } 9 | 10 | try { 11 | if (typeof document === 'undefined') { 12 | throwError('mount must be run in a browser environment like PhantomJS, jsdom or chrome') 13 | } 14 | } catch (error) { 15 | throwError('mount must be run in a browser environment like PhantomJS, jsdom or chrome') 16 | } 17 | 18 | try { 19 | document.querySelector(selector) 20 | return true 21 | } catch (error) { 22 | return false 23 | } 24 | } 25 | 26 | export function isVueComponent (component) { 27 | if (typeof component === 'function' && component.options) { 28 | return true 29 | } 30 | 31 | if (component === null) { 32 | return false 33 | } 34 | 35 | if (typeof component !== 'object') { 36 | return false 37 | } 38 | 39 | if (component.extends) { 40 | return true 41 | } 42 | 43 | if (component._Ctor) { 44 | return true 45 | } 46 | 47 | return typeof component.render === 'function' 48 | } 49 | 50 | export function isRefSelector (refOptionsObject) { 51 | if (typeof refOptionsObject !== 'object') { 52 | return false 53 | } 54 | 55 | if (refOptionsObject === null) { 56 | return false 57 | } 58 | 59 | const validFindKeys = ['ref'] 60 | const entries = Object.entries(refOptionsObject) 61 | 62 | if (!entries.length) { 63 | return false 64 | } 65 | 66 | const isValid = entries.every(([key, value]) => { 67 | return validFindKeys.includes(key) && typeof value === 'string' 68 | }) 69 | 70 | return isValid 71 | } 72 | 73 | export function isNameSelector (nameOptionsObject) { 74 | if (typeof nameOptionsObject !== 'object') { 75 | return false 76 | } 77 | 78 | if (nameOptionsObject === null) { 79 | return false 80 | } 81 | 82 | return !!nameOptionsObject.name 83 | } 84 | 85 | export function isValidSelector (selector) { 86 | if (isDomSelector(selector)) { 87 | return true 88 | } 89 | 90 | if (isVueComponent(selector)) { 91 | return true 92 | } 93 | 94 | if (isNameSelector(selector)) { 95 | return true 96 | } 97 | 98 | return isRefSelector(selector) 99 | } 100 | -------------------------------------------------------------------------------- /src/createWrapperHelpers.js: -------------------------------------------------------------------------------- 1 | import equal from 'deep-equal' 2 | import { Wrapper } from './fixtures' 3 | import { throwError, isValidSelector } from './utils' 4 | 5 | export default function () { 6 | const proto = Wrapper.prototype 7 | 8 | /** 9 | * An alias for `contains` 10 | */ 11 | proto.has = proto.contains 12 | 13 | /** 14 | * Assert that the wrapper contains all provided selectors. 15 | */ 16 | proto.containsAll = proto.hasAll = function (...selectors) { 17 | return selectors.every(selector => this.contains(selector)) 18 | } 19 | 20 | /** 21 | * Assert that the wrapper contains any of the provided selectors. 22 | */ 23 | proto.containsAny = proto.hasAny = function (...selectors) { 24 | return selectors.some(selector => this.contains(selector)) 25 | } 26 | 27 | /** 28 | * Assert that the wrapper contains none of the provided selectors. 29 | */ 30 | proto.containsNone = proto.hasNone = proto.doesntHaveAny = function () { 31 | return !this.containsAny(...arguments) 32 | } 33 | 34 | /** 35 | * Assert that the wrapper's element has the provided class name(s). 36 | */ 37 | proto.hasClass = proto.hasClasses = function (...names) { 38 | return names.every(name => this.classes().includes(name)) 39 | } 40 | 41 | /** 42 | * Assert that the wrapper's element has the provided attribute. 43 | */ 44 | proto.hasAttribute = function (key, value) { 45 | return this.attributes()[key] === value 46 | } 47 | 48 | /** 49 | * Assert that the wrapper has the provided prop. 50 | */ 51 | proto.hasProp = function (key, value) { 52 | if (!this.vm) { 53 | throwError('wrapper.hasProp must be called on a Vue instance') 54 | } 55 | return this.props()[key] === value 56 | } 57 | 58 | /** 59 | * An alias for attributes().id, because we have wrapper.classes(). 60 | */ 61 | proto.id = function () { 62 | return this.attributes().id 63 | } 64 | 65 | /** 66 | * Proxy the most common event triggers. 67 | */ 68 | ;['click', 'dblclick', 'submit', 'input', 'focus', 'blur', 'change'].forEach(eventName => { 69 | proto[eventName] = function () { 70 | if (arguments.length === 0) { 71 | this.trigger(eventName) 72 | return this 73 | } 74 | 75 | if (!isValidSelector(arguments[0])) { 76 | // the first argument must be an options object 77 | if (typeof (arguments[0]) !== 'object') { 78 | throwError(`first argument of ${eventName}() must be a valid selector or an options object`) 79 | } 80 | this.trigger(eventName, arguments[0]) 81 | return this 82 | } 83 | 84 | // the first argument is a valid selector. 85 | // we find() it and trigger the event, optionally with the options object. 86 | arguments.length === 1 87 | ? this.find(arguments[0]).trigger(eventName) 88 | : this.find(arguments[0]).trigger(eventName, arguments[1]) 89 | 90 | return this 91 | } 92 | }) 93 | 94 | /** 95 | * Set the contained element's value and return the wrapper, useful for chaining. 96 | * e.g. wrapper.setValue('foo').click() 97 | */ 98 | proto.setValue = function (value) { 99 | this.element.value = value 100 | return this 101 | } 102 | 103 | /** 104 | * Get the contained element's value. 105 | */ 106 | proto.getValue = function () { 107 | return this.element.value 108 | } 109 | 110 | /** 111 | * Allow getting/setting contained element value directly via wrapper.value. 112 | */ 113 | Object.defineProperty(proto, 'value', { 114 | get () { 115 | return this.getValue() 116 | }, 117 | set (value) { 118 | this.setValue(value) 119 | }, 120 | configurable: true 121 | }) 122 | 123 | /** 124 | * Assert that an event and optionally its value have been emitted. 125 | */ 126 | proto.hasEmitted = function () { 127 | if (arguments.length === 1) { 128 | return Object.keys(this.emitted()).includes(arguments[0]) 129 | } 130 | 131 | if (arguments.length === 2) { 132 | if (!Object.keys(this.emitted()).includes(arguments[0])) { 133 | return false 134 | } 135 | 136 | for (let emittedValue of this.emitted()[arguments[0]]) { 137 | if (equal([arguments[1]], emittedValue)) { 138 | return true 139 | } 140 | } 141 | 142 | return false 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /test/helpers.spec.js: -------------------------------------------------------------------------------- 1 | import { mount as originalMount, shallowMount as originalShallow } from '@vue/test-utils' 2 | import Basic from './components/Basic.vue' 3 | import Contains from './components/Contains.vue' 4 | import Events from './components/Events.vue' 5 | import Inputs from './components/Inputs.vue' 6 | import Props from './components/Props.vue' 7 | import setupHelpers from '../src' 8 | 9 | describe('vue-test-helpers', () => { 10 | setupHelpers() 11 | 12 | it('registers mount and shallow globally', () => { 13 | mount.should.equal(originalMount) 14 | shallowMount.should.equal(originalShallow) 15 | }) 16 | 17 | it('has', () => { 18 | const wrapper = mount(Basic) 19 | wrapper.has.should.equal(wrapper.contains) 20 | }) 21 | 22 | it('hasAll', () => { 23 | const wrapper = shallowMount(Contains) 24 | wrapper.hasAll('.foo', '.bar').should.be.true 25 | wrapper.containsAll('.foo', '.baz').should.be.false 26 | }) 27 | 28 | it('hasAny', () => { 29 | const wrapper = shallowMount(Contains) 30 | wrapper.hasAny('.foo', '.bar').should.be.true 31 | wrapper.containsAny('.foo', '.baz').should.be.true 32 | wrapper.hasAny('.baz', '.qux').should.be.false 33 | }) 34 | 35 | it('hasNone', () => { 36 | const wrapper = shallowMount(Contains) 37 | wrapper.hasNone('.foo', '.bar').should.be.false 38 | wrapper.containsNone('.foo', '.baz').should.be.false 39 | wrapper.doesntHaveAny('.baz', '.qux').should.be.true 40 | }) 41 | 42 | it('hasClass(es)', () => { 43 | const wrapper = shallowMount(Basic) 44 | wrapper.find('.foo').hasClass('foo').should.be.true 45 | wrapper.find('.foo').hasClasses('foo', 'fooo').should.be.true 46 | }) 47 | 48 | it('hasAttribute', () => { 49 | const wrapper = shallowMount(Basic) 50 | wrapper.find('.disabled').hasAttribute('disabled', 'disabled').should.be.true 51 | }) 52 | 53 | it('hasProp', () => { 54 | const wrapper = mount(Props, { propsData: { 55 | foo: 'bar' 56 | }}) 57 | wrapper.hasProp('foo', 'bar').should.be.true 58 | }) 59 | 60 | it('id', () => { 61 | const wrapper = shallowMount(Basic) 62 | wrapper.find('#bar').id().should.equal('bar') 63 | }) 64 | 65 | it('triggers events without an argument', () => { 66 | const wrapper = shallowMount(Events) 67 | const clickStub = sinon.stub(wrapper.vm, 'click') 68 | const dblclickStub = sinon.stub(wrapper.vm, 'dblclick') 69 | const submitStub = sinon.stub(wrapper.vm, 'submit') 70 | wrapper.find('.click').click() 71 | wrapper.find('.dblclick').dblclick() 72 | wrapper.find('form').submit() 73 | clickStub.called.should.be.true 74 | dblclickStub.called.should.be.true 75 | submitStub.calledWith('foo').should.be.true 76 | 77 | clickStub.restore() 78 | dblclickStub.restore() 79 | submitStub.restore() 80 | }) 81 | 82 | it('triggers events with a selector', () => { 83 | const wrapper = shallowMount(Events) 84 | const clickStub = sinon.stub(wrapper.vm, 'click') 85 | wrapper.click('.click') 86 | clickStub.called.should.be.true 87 | clickStub.restore() 88 | }) 89 | 90 | it('triggers events with an options object', () => { 91 | const wrapper = shallowMount(Events) 92 | const inputWrapper = wrapper.find('.click') 93 | const triggerStub = sinon.stub(inputWrapper, 'trigger') 94 | inputWrapper.click({ shiftKey: true }) 95 | triggerStub.calledWith('click', { shiftKey: true }).should.be.true 96 | triggerStub.restore() 97 | }) 98 | 99 | it('gets/sets values', () => { 100 | const wrapper = shallowMount(Inputs) 101 | wrapper.find('.foo').value = 'Bar' 102 | wrapper.find('.foo').element.value.should.equal('Bar') 103 | wrapper.find('.foo').element.value = 'Baz' 104 | wrapper.find('.foo').value.should.equal('Baz') 105 | }) 106 | 107 | it('setValue', () => { 108 | const wrapper = shallowMount(Inputs) 109 | const input = wrapper.find('.foo') 110 | input.setValue('Foo').should.equal(input) 111 | wrapper.find('.foo').element.value.should.equal('Foo') 112 | }) 113 | 114 | it('getValue', () => { 115 | const wrapper = shallowMount(Inputs) 116 | wrapper.find('.foo').setValue('Foo') 117 | wrapper.find('.foo').element.value.should.equal('Foo') 118 | }) 119 | 120 | it('hasEmitted', () => { 121 | const wrapper = shallowMount(Events) 122 | wrapper.find('.click').click() 123 | wrapper.find('.dblclick').dblclick() 124 | wrapper.hasEmitted('clicked').should.be.true 125 | wrapper.hasEmitted('clicked', 10).should.be.true 126 | wrapper.hasEmitted('dblclicked', [41, 42]).should.be.true 127 | }) 128 | }) 129 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-test-helpers [![Build Status](https://travis-ci.org/phanan/vue-test-helpers.svg?branch=master)](https://travis-ci.org/phanan/vue-test-helpers) 2 | 3 | Helpers and syntactic sugars on top of [vue-test-utils](https://github.com/vuejs/vue-test-utils). 4 | 5 | ## Install 6 | 7 | First install the package with yarn or npm: 8 | 9 | ```bash 10 | $ yarn add vue-test-helpers --dev 11 | ``` 12 | 13 | Also you'll need a peer dependency of `vue-test-utils`. Install it with: 14 | 15 | ```bash 16 | $ yarn add @vue/test-utils --dev 17 | ``` 18 | 19 | Then, before your tests (for example in a setup script), import and call the function: 20 | 21 | ```js 22 | import setupHelpers from 'vue-test-helpers' 23 | 24 | setupHelpers() 25 | ``` 26 | 27 | This will do two things: 28 | 29 | 1. 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. 30 | 2. Add some helpers and syntactic sugars on top of `Wrapper` to create your test a better experience. See the next section for details. 31 | 32 | ## Available helpers 33 | 34 | > 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. 35 | 36 | * **`.has(selector)`**: alias for [`.contains(selector)`](https://vue-test-utils.vuejs.org/api/wrapper-array/contains.html) 37 | ```js 38 | expect(wrapper.has('p')).toBe(true) 39 | expect(wrapper.has('#foo')).toBe(true) 40 | expect(wrapper.has(childComponent)).toBe(false) 41 | ``` 42 | * **`.hasAll|containsAll(...selectors)`**: asserts that the wrapper has all provided selectors 43 | ```js 44 | expect(wrapper.hasAll('p', '#foo', childComponent)).toBe(false) 45 | ``` 46 | * **`.hasAny|containsAny(...selectors)`**: asserts that the wrapper has any of the provided selectors 47 | ```js 48 | expect(wrapper.hasAny('p', '#foo', childComponent)).toBe(true) 49 | ``` 50 | * **`.hasNone|containsNone(...selectors)`**: asserts that the wrapper has none of the provided selectors 51 | ```js 52 | expect(wrapper.hasNone('p', '#foo', childComponent)).toBe(false) 53 | ``` 54 | * **`.hasClass|hasClasses(...classes)`**: asserts that the wrapper has the CSS class(es). 55 | ```js 56 | expect(wrapper.find('.foo').hasClass('foo')).toBe(true) 57 | expect(wrapper.find('.foo.bar').hasClasses('foo', 'bar')).toBe(true) 58 | ``` 59 | * **`.hasAttribute(name, value)`**: asserts that the wrapper has an attribute `name` with the value `value` 60 | ```js 61 | expect(wrapper.find('[foo="bar"]').hasAttribute('foo', 'bar')).toBe(true) 62 | ``` 63 | * **`.hasProp(name, value)`**: asserts that the wrapper has a prop `name` with the value `value` 64 | ```js 65 | expect(wrapper.hasProp('foo', 'bar')).toBe(true) 66 | ``` 67 | > Note: `hasClass`, `hasAttribute`, and `hasProp` are actually available in `vue-test-utils`, but marked as deprecated and will be removed in 1.0. 68 | * **`.hasEmitted(name[, value])`**: asserts that an event `name` has been emitted, optionally with a value `value` 69 | ```js 70 | wrapper.vm.$emit('foo', 'bar') 71 | expect(wrapper.hasEmitted('foo')).toBe(true) 72 | expect(wrapper.hasEmitted('foo', 'bar')).toBe(true) 73 | ``` 74 | * **`.id()`**: gets the id of the contained element 75 | ```js 76 | expect(wrapper.find('#foo').id()).toBe('foo') 77 | ``` 78 | * **`.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. 79 | ```js 80 | expect(wrapper.click().hasEmitted('clicked')).toBe(true) 81 | expect(wrapper.click({ button: 1 }).hasEmitted('rightClicked')).toBe(true) 82 | ``` 83 | * **`.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. 84 | ```js 85 | expect(wrapper.click('button').hasEmitted('buttonClicked')).toBe(true) 86 | expect(wrapper.click('button', { ctrlKey: true }).hasEmitted('buttonCtrlClicked')).toBe(true) 87 | ``` 88 | * **`.setValue(value)`**: sets the value of the contained (input) element. This method returns the called instance, useful for chaining. 89 | ```js 90 | wrapper.find('input').setValue('foo').change() 91 | ``` 92 | * **`.getValue()`**: gets the value of the contained (input) element 93 | ```js 94 | expect(wrapper.find('input').setValue('foo').getValue()).toBe('foo') 95 | ``` 96 | * **`.value`**: a proxy for the value of the contained (input) element 97 | ```js 98 | wrapper.find('input').value = 'foo' 99 | expect(wrapper.find('input').value).toBe('foo') 100 | ``` 101 | 102 | ## License 103 | 104 | MIT © [Phan An](https://phanan.net) 105 | -------------------------------------------------------------------------------- /dist/vue-test-helpers.min.js: -------------------------------------------------------------------------------- 1 | module.exports=function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={i:d,l:!1,exports:{}};return a[d].call(e.exports,e,e.exports,b),e.l=!0,e.exports}var c={};return b.m=a,b.c=c,b.d=function(a,c,d){b.o(a,c)||Object.defineProperty(a,c,{configurable:!1,enumerable:!0,get:d})},b.n=function(a){var c=a&&a.__esModule?function(){return a['default']}:function(){return a};return b.d(c,'a',c),c},b.o=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},b.p='',b(b.s=1)}([function(a){a.exports=require('@vue/test-utils')},function(a,b,c){'use strict';(function(d){Object.defineProperty(b,'__esModule',{value:!0}),b.default=function(){var b=0