diff --git a/.eslintignore b/.eslintignore index 1521c8b76..884a2323e 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1 @@ -dist +**/dist/** diff --git a/.gitignore b/.gitignore index 63161737b..8161b78c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store node_modules/ +.eslintcache # Editor files /.idea diff --git a/.prettierrc.json b/.prettierrc.json index b2095be81..f79acadcb 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,4 +1,6 @@ { "semi": false, - "singleQuote": true + "singleQuote": true, + "trailingComma": "none", + "arrowParens": "avoid" } diff --git a/docs/api/options.md b/docs/api/options.md index 3fa3b0548..68efd2eeb 100644 --- a/docs/api/options.md +++ b/docs/api/options.md @@ -169,7 +169,7 @@ You can also pass a function that takes the props as an argument: ```js shallowMount(Component, { scopedSlots: { - foo: function(props) { + foo: function (props) { return this.$createElement('div', props.index) } } diff --git a/docs/fr/api/options.md b/docs/fr/api/options.md index ed2171e5f..c4a13604d 100644 --- a/docs/fr/api/options.md +++ b/docs/fr/api/options.md @@ -168,7 +168,7 @@ Vous pouvez également passer une fonction qui prend les props comme argument : ```js shallowMount(Component, { scopedSlots: { - foo: function(props) { + foo: function (props) { return this.$createElement('div', props.index) } } diff --git a/docs/fr/guides/common-tips.md b/docs/fr/guides/common-tips.md index f9dad1e0f..da6e8d863 100644 --- a/docs/fr/guides/common-tips.md +++ b/docs/fr/guides/common-tips.md @@ -221,7 +221,7 @@ En pratique, bien que nous appelions et attendions `setData` pour assurer la mis ```js const transitionStub = () => ({ - render: function(h) { + render: function (h) { return this.$options._renderChildren } }) diff --git a/docs/fr/guides/dom-events.md b/docs/fr/guides/dom-events.md index b90f33ea2..0d8bce39e 100644 --- a/docs/fr/guides/dom-events.md +++ b/docs/fr/guides/dom-events.md @@ -144,7 +144,7 @@ Ce composant permet d'incrémenter/décrémenter la quantité à l'aide de diff }, watch: { - quantity: function(newValue) { + quantity: function (newValue) { this.$emit('input', newValue) } } diff --git a/docs/fr/installation/using-other-test-runners.md b/docs/fr/installation/using-other-test-runners.md index d019ec8a9..2ad784d22 100644 --- a/docs/fr/installation/using-other-test-runners.md +++ b/docs/fr/installation/using-other-test-runners.md @@ -12,7 +12,7 @@ Vous trouverez ci-dessous une configuration de base de Karma pour Vue Test Utils // karma.conf.js var webpackConfig = require('./webpack.config.js') -module.exports = function(config) { +module.exports = function (config) { config.set({ frameworks: ['mocha'], files: ['test/**/*.spec.js'], diff --git a/docs/guides/common-tips.md b/docs/guides/common-tips.md index e394786a3..240119ebf 100644 --- a/docs/guides/common-tips.md +++ b/docs/guides/common-tips.md @@ -223,7 +223,7 @@ In practice, although we are calling and awaiting `setData` to ensure the DOM is ```js const transitionStub = () => ({ - render: function(h) { + render: function (h) { return this.$options._renderChildren } }) diff --git a/docs/guides/dom-events.md b/docs/guides/dom-events.md index df0988d45..d203a740c 100644 --- a/docs/guides/dom-events.md +++ b/docs/guides/dom-events.md @@ -142,7 +142,7 @@ This component allows to increment/decrement the quantity using various keys. }, watch: { - quantity: function(newValue) { + quantity: function (newValue) { this.$emit('input', newValue) } } diff --git a/docs/installation/using-other-test-runners.md b/docs/installation/using-other-test-runners.md index 0b49972e0..48349f267 100644 --- a/docs/installation/using-other-test-runners.md +++ b/docs/installation/using-other-test-runners.md @@ -12,7 +12,7 @@ Following is a basic Karma config for Vue Test Utils: // karma.conf.js var webpackConfig = require('./webpack.config.js') -module.exports = function(config) { +module.exports = function (config) { config.set({ frameworks: ['mocha'], files: ['test/**/*.spec.js'], diff --git a/docs/installation/using-with-jest.md b/docs/installation/using-with-jest.md index c6a49b0c5..5f9167934 100644 --- a/docs/installation/using-with-jest.md +++ b/docs/installation/using-with-jest.md @@ -17,7 +17,7 @@ The plugin pulls all required dependencies (including jest), creates a `jest.con After that, all you need to do is to install Vue Test Utils. ```bash -$ npm install --save-dev @vue/test-utils +$ npm install --save-dev @vue/test-utils@legacy ``` ### Manual installation @@ -25,7 +25,7 @@ $ npm install --save-dev @vue/test-utils After setting up Jest, the first thing to do is to install Vue Test Utils and [`vue-jest`](https://github.com/vuejs/vue-jest) to process Single-File Components: ```bash -$ npm install --save-dev @vue/test-utils vue-jest +$ npm install --save-dev @vue/test-utils@legacy vue-jest ``` Then, you need to tell Jest to transform `.vue` files using `vue-jest`. You can do so by adding the following configuration in `package.json` or in a standalone [Jest config file](https://jestjs.io/docs/en/configuration): diff --git a/docs/ja/api/options.md b/docs/ja/api/options.md index 7f6a550bd..8d4e8e7cc 100644 --- a/docs/ja/api/options.md +++ b/docs/ja/api/options.md @@ -94,7 +94,7 @@ props を引数に取る関数を渡すことができます。 ```js shallowMount(Component, { scopedSlots: { - foo: function(props) { + foo: function (props) { return this.$createElement('div', props.index) } } diff --git a/docs/ja/guides/dom-events.md b/docs/ja/guides/dom-events.md index 3a3f35aaa..562117299 100644 --- a/docs/ja/guides/dom-events.md +++ b/docs/ja/guides/dom-events.md @@ -134,7 +134,7 @@ it('Click on yes button calls our method with argument "yes"', async () => { } }, watch: { - quantity: function(newValue) { + quantity: function (newValue) { this.$emit('input', newValue) } } diff --git a/docs/ja/guides/getting-started.md b/docs/ja/guides/getting-started.md index d085eb9c7..cdcf63728 100644 --- a/docs/ja/guides/getting-started.md +++ b/docs/ja/guides/getting-started.md @@ -131,7 +131,7 @@ it('will catch the error using done', done => { }) it('will catch the error using a promise', () => { - return Vue.nextTick().then(function() { + return Vue.nextTick().then(function () { expect(true).toBe(false) }) }) diff --git a/docs/ja/installation/testing-single-file-components-with-karma.md b/docs/ja/installation/testing-single-file-components-with-karma.md index 26ef15c6b..9e2c91f2a 100644 --- a/docs/ja/installation/testing-single-file-components-with-karma.md +++ b/docs/ja/installation/testing-single-file-components-with-karma.md @@ -36,7 +36,7 @@ npm install --save-dev @vue/test-utils karma karma-chrome-launcher karma-mocha k var webpackConfig = require('./webpack.config.js') -module.exports = function(config) { +module.exports = function (config) { config.set({ frameworks: ['mocha'], @@ -160,7 +160,7 @@ npm install --save-dev babel-plugin-istanbul ```js // karma.conf.js -module.exports = function(config) { +module.exports = function (config) { config.set({ // ... diff --git a/docs/ru/api/options.md b/docs/ru/api/options.md index 40968a0bc..afeb619f3 100644 --- a/docs/ru/api/options.md +++ b/docs/ru/api/options.md @@ -107,7 +107,7 @@ shallowMount(Component, { ```js shallowMount(Component, { scopedSlots: { - foo: function(props) { + foo: function (props) { return this.$createElement('div', props.index) } } diff --git a/docs/ru/guides/dom-events.md b/docs/ru/guides/dom-events.md index b3ce272cb..5f472fc95 100644 --- a/docs/ru/guides/dom-events.md +++ b/docs/ru/guides/dom-events.md @@ -136,7 +136,7 @@ describe('Click event', () => { }, watch: { - quantity: function(newValue) { + quantity: function (newValue) { this.$emit('input', newValue) } } diff --git a/docs/ru/guides/getting-started.md b/docs/ru/guides/getting-started.md index 77b324fa2..a4cc198d7 100644 --- a/docs/ru/guides/getting-started.md +++ b/docs/ru/guides/getting-started.md @@ -131,7 +131,7 @@ it('должен отлавливать ошибку с использовани }) it('должен отлавливать ошибку с использованием promise', () => { - return Vue.nextTick().then(function() { + return Vue.nextTick().then(function () { expect(true).toBe(false) }) }) diff --git a/docs/ru/installation/testing-single-file-components-with-karma.md b/docs/ru/installation/testing-single-file-components-with-karma.md index 0105006e2..fe2cacf8a 100644 --- a/docs/ru/installation/testing-single-file-components-with-karma.md +++ b/docs/ru/installation/testing-single-file-components-with-karma.md @@ -36,7 +36,7 @@ npm install --save-dev @vue/test-utils karma karma-chrome-launcher karma-mocha k var webpackConfig = require('./webpack.config.js') -module.exports = function(config) { +module.exports = function (config) { config.set({ frameworks: ['mocha'], @@ -160,7 +160,7 @@ npm install --save-dev babel-plugin-istanbul ```js // karma.conf.js -module.exports = function(config) { +module.exports = function (config) { config.set({ // ... diff --git a/docs/zh/api/options.md b/docs/zh/api/options.md index 076090228..40b86c2ad 100644 --- a/docs/zh/api/options.md +++ b/docs/zh/api/options.md @@ -167,7 +167,7 @@ shallowMount(Component, { ```js shallowMount(Component, { scopedSlots: { - foo: function(props) { + foo: function (props) { return this.$createElement('div', props.index) } } diff --git a/docs/zh/guides/common-tips.md b/docs/zh/guides/common-tips.md index 110fc0a96..780c980c9 100644 --- a/docs/zh/guides/common-tips.md +++ b/docs/zh/guides/common-tips.md @@ -222,7 +222,7 @@ test('should render Foo, then hide it', async () => { ```js const transitionStub = () => ({ - render: function(h) { + render: function (h) { return this.$options._renderChildren } }) diff --git a/docs/zh/guides/dom-events.md b/docs/zh/guides/dom-events.md index a3c858807..1af79fc2a 100644 --- a/docs/zh/guides/dom-events.md +++ b/docs/zh/guides/dom-events.md @@ -142,7 +142,7 @@ it('Click on yes button calls our method with argument "yes"', async () => { }, watch: { - quantity: function(newValue) { + quantity: function (newValue) { this.$emit('input', newValue) } } diff --git a/docs/zh/guides/getting-started.md b/docs/zh/guides/getting-started.md index 70f35f93b..7b10a0336 100644 --- a/docs/zh/guides/getting-started.md +++ b/docs/zh/guides/getting-started.md @@ -164,7 +164,7 @@ it('will catch the error using done', done => { }) it('will catch the error using a promise', () => { - return Vue.nextTick().then(function() { + return Vue.nextTick().then(function () { expect(true).toBe(false) }) }) diff --git a/docs/zh/installation/testing-single-file-components-with-karma.md b/docs/zh/installation/testing-single-file-components-with-karma.md index 544ae4521..a1a5dc19c 100644 --- a/docs/zh/installation/testing-single-file-components-with-karma.md +++ b/docs/zh/installation/testing-single-file-components-with-karma.md @@ -36,7 +36,7 @@ npm install --save-dev @vue/test-utils karma karma-chrome-launcher karma-mocha k var webpackConfig = require('./webpack.config.js') -module.exports = function(config) { +module.exports = function (config) { config.set({ frameworks: ['mocha'], @@ -160,7 +160,7 @@ npm install --save-dev babel-plugin-istanbul ```js // karma.conf.js -module.exports = function(config) { +module.exports = function (config) { config.set({ // ... diff --git a/lerna.json b/lerna.json index 77f280927..1353e8b6a 100644 --- a/lerna.json +++ b/lerna.json @@ -5,5 +5,5 @@ ], "npmClient": "yarn", "useWorkspaces": true, - "version": "1.3.3" + "version": "1.3.5" } diff --git a/package.json b/package.json index 4ada8c2e2..d75249253 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,10 @@ "docs": "vuepress dev docs", "docs:build": "vuepress build docs", "flow": "flow check", - "lint": "eslint --ext js,vue .", + "lint": "eslint --ext js,vue . --cache", "lint:docs": "eslint --ext js,vue,md docs --ignore-path .gitignore", "lint:fix": "yarn lint -- --fix", - "format": "prettier --write \"**/*.{js,json,vue,md}\"", + "format": "prettier --write \"**/*.{js,json,vue,md}\" --cache", "format:check": "prettier --check \"**/*.{js,json,vue,md}\"", "release": "yarn build && yarn test:unit && lerna publish --conventional-commits -m \"chore(release): publish %s\"", "test": "yarn format:check && yarn lint && yarn lint:docs && yarn flow && yarn test:types && yarn test:unit -w 1 && yarn test:unit:browser", @@ -91,7 +91,7 @@ "karma-spec-reporter": "^0.0.32", "karma-webpack": "^4.0.2", "lint-staged": "^9.5.0", - "prettier": "^1.16.0", + "prettier": "^2.8.1", "puppeteer": "^5.2.1", "rollup-plugin-delete": "^2.0.0", "@rollup/plugin-replace": "^2.3.3", diff --git a/packages/create-instance/add-mocks.js b/packages/create-instance/add-mocks.js index 3675e4459..268d221fe 100644 --- a/packages/create-instance/add-mocks.js +++ b/packages/create-instance/add-mocks.js @@ -1,6 +1,6 @@ // @flow import $$Vue from 'vue' -import { warn } from 'shared/util' +import { warn, keys } from 'shared/util' export default function addMocks( _Vue: Component, @@ -9,7 +9,7 @@ export default function addMocks( if (mockedProperties === false) { return } - Object.keys(mockedProperties).forEach(key => { + keys(mockedProperties).forEach(key => { try { // $FlowIgnore _Vue.prototype[key] = mockedProperties[key] diff --git a/packages/create-instance/create-component-stubs.js b/packages/create-instance/create-component-stubs.js index 0b8f8d094..aa29e0012 100644 --- a/packages/create-instance/create-component-stubs.js +++ b/packages/create-instance/create-component-stubs.js @@ -195,7 +195,7 @@ export function createStubsFromStubsObject( stubs: Object, _Vue: Component ): Components { - return Object.keys(stubs || {}).reduce((acc, stubName) => { + return keys(stubs || {}).reduce((acc, stubName) => { let stub = stubs[stubName] validateStub(stub) diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index 3c0ba7d2e..9fb4208da 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -10,6 +10,7 @@ import { componentNeedsCompiling, isConstructor } from 'shared/validators' import createScopedSlots from './create-scoped-slots' import { createStubsFromStubsObject } from './create-component-stubs' import { patchCreateElement } from './patch-create-element' +import { keys } from 'shared/util' function createContext(options, scopedSlots, currentProps) { const on = { @@ -86,8 +87,8 @@ export default function createInstance( // watchers provided in mounting options should override preexisting ones if (componentOptions.watch && instanceOptions.watch) { - const componentWatchers = Object.keys(componentOptions.watch) - const instanceWatchers = Object.keys(instanceOptions.watch) + const componentWatchers = keys(componentOptions.watch) + const instanceWatchers = keys(instanceOptions.watch) for (let i = 0; i < instanceWatchers.length; i++) { const k = instanceWatchers[i] @@ -107,7 +108,7 @@ export default function createInstance( const parentComponentOptions = options.parentComponent || {} const originalParentComponentProvide = parentComponentOptions.provide - parentComponentOptions.provide = function() { + parentComponentOptions.provide = function () { return { ...getValuesFromCallableOption.call(this, originalParentComponentProvide), // $FlowIgnore @@ -116,7 +117,7 @@ export default function createInstance( } const originalParentComponentData = parentComponentOptions.data - parentComponentOptions.data = function() { + parentComponentOptions.data = function () { return { ...getValuesFromCallableOption.call(this, originalParentComponentData), vueTestUtils_childProps: { ...options.propsData } @@ -126,7 +127,7 @@ export default function createInstance( parentComponentOptions.$_doNotStubChildren = true parentComponentOptions.$_isWrapperParent = true parentComponentOptions._isFunctionalContainer = componentOptions.functional - parentComponentOptions.render = function(h) { + parentComponentOptions.render = function (h) { return h( Constructor, createContext(options, scopedSlots, this.vueTestUtils_childProps), diff --git a/packages/create-instance/create-scoped-slots.js b/packages/create-instance/create-scoped-slots.js index 50464d9ee..daa4f3cb1 100644 --- a/packages/create-instance/create-scoped-slots.js +++ b/packages/create-instance/create-scoped-slots.js @@ -8,9 +8,9 @@ function isDestructuringSlotScope(slotScope: string): boolean { return /^{.*}$/.test(slotScope) } -function getVueTemplateCompilerHelpers( - _Vue: Component -): { [name: string]: Function } { +function getVueTemplateCompilerHelpers(_Vue: Component): { + [name: string]: Function +} { // $FlowIgnore const vue = new _Vue() const helpers = {} @@ -111,7 +111,7 @@ export default function createScopedSlots( const slotScope = scopedSlotMatches.match && scopedSlotMatches.match[1] - scopedSlots[scopedSlotName] = function(props) { + scopedSlots[scopedSlotName] = function (props) { let res if (isFn) { res = renderFn.call({ ...helpers }, props) diff --git a/packages/create-instance/log-events.js b/packages/create-instance/log-events.js index 9de6abf20..c3fd97f0d 100644 --- a/packages/create-instance/log-events.js +++ b/packages/create-instance/log-events.js @@ -15,7 +15,7 @@ export function logEvents( export function addEventLogger(_Vue: Component): void { _Vue.mixin({ - beforeCreate: function() { + beforeCreate: function () { this.__emitted = Object.create(null) this.__emittedByOrder = [] logEvents(this, this.__emitted, this.__emittedByOrder) diff --git a/packages/server-test-utils/dist/vue-server-test-utils.js b/packages/server-test-utils/dist/vue-server-test-utils.js index 4190a0872..cf5f0a217 100644 --- a/packages/server-test-utils/dist/vue-server-test-utils.js +++ b/packages/server-test-utils/dist/vue-server-test-utils.js @@ -1750,7 +1750,7 @@ function isVueComponent(c) { return true } - if (c === null || typeof c !== 'object') { + if (!isPlainObject(c)) { return false } @@ -1780,8 +1780,8 @@ function componentNeedsCompiling(component) { function isRefSelector(refOptionsObject) { if ( - typeof refOptionsObject !== 'object' || - Object.keys(refOptionsObject || {}).length !== 1 + !isPlainObject(refOptionsObject) || + keys$1(refOptionsObject || {}).length !== 1 ) { return false } @@ -1790,7 +1790,7 @@ function isRefSelector(refOptionsObject) { } function isNameSelector(nameOptionsObject) { - if (typeof nameOptionsObject !== 'object' || nameOptionsObject === null) { + if (!isPlainObject(nameOptionsObject)) { return false } @@ -1806,7 +1806,7 @@ function isDynamicComponent(c) { } function isComponentOptions(c) { - return c !== null && typeof c === 'object' && (c.template || c.render) + return isPlainObject(c) && (c.template || c.render) } function isFunctionalComponent(c) { @@ -1848,10 +1848,10 @@ function makeMap(str, expectsLowerCase) { map[list[i]] = true; } return expectsLowerCase - ? function(val) { + ? function (val) { return map[val.toLowerCase()] } - : function(val) { + : function (val) { return map[val] } } @@ -1923,7 +1923,7 @@ function vmCtorMatches(vm, component) { } if (component.functional) { - return Object.keys(vm._Ctor || {}).some(function (c) { + return keys$1(vm._Ctor || {}).some(function (c) { return component === vm._Ctor[c].extendOptions }) } @@ -2105,7 +2105,7 @@ function getOption(option, config) { if (option === false) { return false } - if (option || (config && Object.keys(config).length > 0)) { + if (option || (config && keys$1(config).length > 0)) { if (option instanceof Function) { return option } @@ -2129,7 +2129,7 @@ function mergeOptions( ) { var mocks = (getOption(options.mocks, config.mocks)); var methods = (getOption(options.methods, config.methods)); - if (methods && Object.keys(methods).length) { + if (methods && keys$1(methods).length) { warnDeprecated( 'overwriting methods via the `methods` property', 'There is no clear migration path for the `methods` property - Vue does not support arbitrarily replacement of methods, nor should VTU. To stub a complex method extract it from the component and test it in isolation. Otherwise, the suggestion is to rethink those tests' @@ -8084,7 +8084,10 @@ ErrorWrapper.prototype.destroy = function destroy () { */ function isStyleVisible(element) { - if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) { + if ( + !(element instanceof window.HTMLElement) && + !(element instanceof window.SVGElement) + ) { return false } @@ -8124,14 +8127,14 @@ function isElementVisible(element, previousElement) { } function recursivelySetData(vm, target, data) { - Object.keys(data).forEach(function (key) { + keys$1(data).forEach(function (key) { var val = data[key]; var targetVal = target[key]; if ( isPlainObject(val) && isPlainObject(targetVal) && - Object.keys(val).length > 0 + keys$1(val).length > 0 ) { recursivelySetData(vm, targetVal, val); } else { @@ -9379,10 +9382,10 @@ var w3cKeys = { esc: 'Esc', escape: 'Escape', space: ' ', - up: 'Up', - left: 'Left', - right: 'Right', - down: 'Down', + up: 'ArrowUp', + left: 'ArrowLeft', + right: 'ArrowRight', + down: 'ArrowDown', end: 'End', home: 'Home', backspace: 'Backspace', @@ -9467,7 +9470,7 @@ function createDOMEvent(type, options) { : createOldEvent(eventParams); var eventPrototype = Object.getPrototypeOf(event); - Object.keys(options || {}).forEach(function (key) { + keys$1(options || {}).forEach(function (key) { var propertyDescriptor = Object.getOwnPropertyDescriptor( eventPrototype, key @@ -9573,17 +9576,14 @@ Wrapper.prototype.classes = function classes (className) { var classes = classAttribute ? classAttribute.split(' ') : []; // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { - var cssModuleIdentifiers = Object.keys(this.vm.$style).reduce( - function (acc, key) { - // $FlowIgnore - var moduleIdent = this$1.vm.$style[key]; - if (moduleIdent) { - acc[moduleIdent.split(' ')[0]] = key; - } - return acc - }, - {} - ); + var cssModuleIdentifiers = keys$1(this.vm.$style).reduce(function (acc, key) { + // $FlowIgnore + var moduleIdent = this$1.vm.$style[key]; + if (moduleIdent) { + acc[moduleIdent.split(' ')[0]] = key; + } + return acc + }, {}); classes = classes.map(function (name) { return cssModuleIdentifiers[name] || name; }); } @@ -9937,7 +9937,7 @@ Wrapper.prototype.overview = function overview () { var computed = this.vm._computedWatchers ? formatJSON.apply( // $FlowIgnore - void 0, Object.keys(this.vm._computedWatchers).map(function (computedKey) { + void 0, keys$1(this.vm._computedWatchers).map(function (computedKey) { var obj; return (( obj = {}, obj[computedKey] = this$1.vm[computedKey], obj )); @@ -9961,9 +9961,7 @@ Wrapper.prototype.overview = function overview () { var emittedJSONReplacer = function (key, value) { return value instanceof Array ? value.map(function (calledWith, index) { var callParams = calledWith.map(function (param) { return typeof param === 'object' - ? JSON.stringify(param) - .replace(/"/g, '') - .replace(/,/g, ', ') + ? JSON.stringify(param).replace(/"/g, '').replace(/,/g, ', ') : param; } ); @@ -10145,7 +10143,7 @@ Wrapper.prototype.setMethods = function setMethods (methods) { } this.__warnIfDestroyed(); - Object.keys(methods).forEach(function (key) { + keys$1(methods).forEach(function (key) { // $FlowIgnore : Problem with possibly null this.vm this$1.vm[key] = methods[key]; // $FlowIgnore : Problem with possibly null this.vm @@ -10184,11 +10182,10 @@ Wrapper.prototype.setProps = function setProps (data) { this.__warnIfDestroyed(); - Object.keys(data).forEach(function (key) { + keys$1(data).forEach(function (key) { // Don't let people set entire objects, because reactivity won't work if ( - typeof data[key] === 'object' && - data[key] !== null && + isPlainObject(data[key]) && // $FlowIgnore : Problem with possibly null this.vm data[key] === this$1.vm[key] ) { @@ -12919,7 +12916,7 @@ function _createLocalVue( var instance = _Vue.extend(); // clone global APIs - Object.keys(_Vue).forEach(function (key) { + keys$1(_Vue).forEach(function (key) { if (!instance.hasOwnProperty(key)) { var original = _Vue[key]; // cloneDeep can fail when cloning Vue instances @@ -12996,7 +12993,7 @@ function compileTemplate(component) { } if (component.components) { - Object.keys(component.components).forEach(function (c) { + keys$1(component.components).forEach(function (c) { var cmp = component.components[c]; if (!cmp.render) { compileTemplate(cmp); @@ -13014,7 +13011,7 @@ function compileTemplate(component) { } function compileTemplateForSlots(slots) { - Object.keys(slots).forEach(function (key) { + keys$1(slots).forEach(function (key) { var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]; slot.forEach(function (slotValue) { if (componentNeedsCompiling(slotValue)) { @@ -13041,7 +13038,7 @@ function requiresTemplateCompiler(slot) { } function validateSlots(slots) { - Object.keys(slots).forEach(function (key) { + keys$1(slots).forEach(function (key) { var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]; slot.forEach(function (slotValue) { @@ -13245,7 +13242,7 @@ function addMocks( if (mockedProperties === false) { return } - Object.keys(mockedProperties).forEach(function (key) { + keys$1(mockedProperties).forEach(function (key) { try { // $FlowIgnore _Vue.prototype[key] = mockedProperties[key]; @@ -13280,7 +13277,7 @@ function logEvents( function addEventLogger(_Vue) { _Vue.mixin({ - beforeCreate: function() { + beforeCreate: function () { this.__emitted = Object.create(null); this.__emittedByOrder = []; logEvents(this, this.__emitted, this.__emittedByOrder); @@ -13328,9 +13325,7 @@ function isDestructuringSlotScope(slotScope) { return /^{.*}$/.test(slotScope) } -function getVueTemplateCompilerHelpers( - _Vue -) { +function getVueTemplateCompilerHelpers(_Vue) { // $FlowIgnore var vue = new _Vue(); var helpers = {}; @@ -13429,7 +13424,7 @@ function createScopedSlots( var slotScope = scopedSlotMatches.match && scopedSlotMatches.match[1]; - scopedSlots[scopedSlotName] = function(props) { + scopedSlots[scopedSlotName] = function (props) { var obj; var res; @@ -13478,10 +13473,10 @@ function resolveComponent$1(obj, component) { ) } -function getCoreProperties(componentOptions) { +function getCoreProperties(componentOptions, name) { return { attrs: componentOptions.attrs, - name: componentOptions.name, + name: componentOptions.name || name, model: componentOptions.model, props: componentOptions.props, on: componentOptions.on, @@ -13542,7 +13537,7 @@ function createStubFromComponent( Vue__default['default'].config.ignoredElements.push(tagName); } - return Object.assign({}, getCoreProperties(componentOptions), + return Object.assign({}, getCoreProperties(componentOptions, name), {$_vueTestUtils_original: originalComponent, $_doNotStubChildren: true, render: function render(h, context) { @@ -13627,7 +13622,7 @@ function createStubsFromStubsObject( ) { if ( originalComponents === void 0 ) originalComponents = {}; - return Object.keys(stubs || {}).reduce(function (acc, stubName) { + return keys$1(stubs || {}).reduce(function (acc, stubName) { var stub = stubs[stubName]; validateStub(stub); @@ -13723,8 +13718,16 @@ function patchCreateElement(_Vue, stubs, stubAllComponents) { } if (isConstructor(el) || isComponentOptions(el)) { + var componentOptions = isConstructor(el) ? el.options : el; + var elName = componentOptions.name; + + var stubbedComponent = resolveComponent(elName, stubs); + if (stubbedComponent) { + return originalCreateElement.apply(void 0, [ stubbedComponent ].concat( args )) + } + if (stubAllComponents) { - var stub = createStubFromComponent(el, el.name || 'anonymous', _Vue); + var stub = createStubFromComponent(el, elName || 'anonymous', _Vue); return originalCreateElement.apply(void 0, [ stub ].concat( args )) } var Constructor = shouldExtend(el) ? extend(el, _Vue) : el; @@ -13837,8 +13840,8 @@ function createInstance( // watchers provided in mounting options should override preexisting ones if (componentOptions.watch && instanceOptions.watch) { - var componentWatchers = Object.keys(componentOptions.watch); - var instanceWatchers = Object.keys(instanceOptions.watch); + var componentWatchers = keys$1(componentOptions.watch); + var instanceWatchers = keys$1(instanceOptions.watch); for (var i = 0; i < instanceWatchers.length; i++) { var k = instanceWatchers[i]; @@ -13858,14 +13861,14 @@ function createInstance( var parentComponentOptions = options.parentComponent || {}; var originalParentComponentProvide = parentComponentOptions.provide; - parentComponentOptions.provide = function() { + parentComponentOptions.provide = function () { return Object.assign({}, getValuesFromCallableOption.call(this, originalParentComponentProvide), // $FlowIgnore getValuesFromCallableOption.call(this, options.provide)) }; var originalParentComponentData = parentComponentOptions.data; - parentComponentOptions.data = function() { + parentComponentOptions.data = function () { return Object.assign({}, getValuesFromCallableOption.call(this, originalParentComponentData), {vueTestUtils_childProps: Object.assign({}, options.propsData)}) }; @@ -13873,7 +13876,7 @@ function createInstance( parentComponentOptions.$_doNotStubChildren = true; parentComponentOptions.$_isWrapperParent = true; parentComponentOptions._isFunctionalContainer = componentOptions.functional; - parentComponentOptions.render = function(h) { + parentComponentOptions.render = function (h) { return h( Constructor, createContext(options, scopedSlots, this.vueTestUtils_childProps), diff --git a/packages/server-test-utils/package.json b/packages/server-test-utils/package.json index c7d8da9f7..ddabb64ee 100644 --- a/packages/server-test-utils/package.json +++ b/packages/server-test-utils/package.json @@ -1,6 +1,6 @@ { "name": "@vue/server-test-utils", - "version": "1.3.3", + "version": "1.3.5", "description": "Utilities for testing Vue components.", "main": "dist/vue-server-test-utils.js", "types": "types/index.d.ts", diff --git a/packages/shared/compile-template.js b/packages/shared/compile-template.js index 49bbdeb91..0d8936767 100644 --- a/packages/shared/compile-template.js +++ b/packages/shared/compile-template.js @@ -2,7 +2,7 @@ import { compileToFunctions } from 'vue-template-compiler' import { componentNeedsCompiling } from './validators' -import { throwError } from './util' +import { throwError, keys } from './util' export function compileTemplate(component: Component): void { if (component.template) { @@ -31,7 +31,7 @@ export function compileTemplate(component: Component): void { } if (component.components) { - Object.keys(component.components).forEach(c => { + keys(component.components).forEach(c => { const cmp = component.components[c] if (!cmp.render) { compileTemplate(cmp) @@ -49,7 +49,7 @@ export function compileTemplate(component: Component): void { } export function compileTemplateForSlots(slots: Object): void { - Object.keys(slots).forEach(key => { + keys(slots).forEach(key => { const slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]] slot.forEach(slotValue => { if (componentNeedsCompiling(slotValue)) { diff --git a/packages/shared/create-local-vue.js b/packages/shared/create-local-vue.js index 6f64d7029..4eabf9811 100644 --- a/packages/shared/create-local-vue.js +++ b/packages/shared/create-local-vue.js @@ -2,6 +2,7 @@ import Vue from 'vue' import cloneDeep from 'lodash/cloneDeep' +import { keys } from './util' /** * Used internally by vue-server-test-utils and test-utils to propagate/create vue instances. @@ -17,7 +18,7 @@ function _createLocalVue( const instance = _Vue.extend() // clone global APIs - Object.keys(_Vue).forEach(key => { + keys(_Vue).forEach(key => { if (!instance.hasOwnProperty(key)) { const original = _Vue[key] // cloneDeep can fail when cloning Vue instances diff --git a/packages/shared/merge-options.js b/packages/shared/merge-options.js index bf8d97418..f70421103 100644 --- a/packages/shared/merge-options.js +++ b/packages/shared/merge-options.js @@ -1,12 +1,12 @@ // @flow import { normalizeStubs, normalizeProvide } from './normalize' -import { warnDeprecated } from 'shared/util' +import { warnDeprecated, keys } from 'shared/util' function getOption(option, config?: Object): any { if (option === false) { return false } - if (option || (config && Object.keys(config).length > 0)) { + if (option || (config && keys(config).length > 0)) { if (option instanceof Function) { return option } @@ -34,7 +34,7 @@ export function mergeOptions( const methods = (getOption(options.methods, config.methods): { [key: string]: Function }) - if (methods && Object.keys(methods).length) { + if (methods && keys(methods).length) { warnDeprecated( 'overwriting methods via the `methods` property', 'There is no clear migration path for the `methods` property - Vue does not support arbitrarily replacement of methods, nor should VTU. To stub a complex method extract it from the component and test it in isolation. Otherwise, the suggestion is to rethink those tests' diff --git a/packages/shared/validate-slots.js b/packages/shared/validate-slots.js index 9806b098d..71df38fd8 100644 --- a/packages/shared/validate-slots.js +++ b/packages/shared/validate-slots.js @@ -1,6 +1,6 @@ // @flow -import { throwError } from 'shared/util' +import { throwError, keys } from 'shared/util' import { compileToFunctions } from 'vue-template-compiler' import { isVueComponent } from './validators' @@ -19,7 +19,7 @@ function requiresTemplateCompiler(slot: any): void { } export function validateSlots(slots: SlotsObject): void { - Object.keys(slots).forEach(key => { + keys(slots).forEach(key => { const slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]] slot.forEach(slotValue => { diff --git a/packages/shared/validators.js b/packages/shared/validators.js index 986049d33..fe0bbab3a 100644 --- a/packages/shared/validators.js +++ b/packages/shared/validators.js @@ -1,5 +1,5 @@ // @flow -import { throwError, capitalize, camelize, hyphenate } from './util' +import { throwError, capitalize, camelize, hyphenate, keys } from './util' export function isDomSelector(selector: any): boolean { if (typeof selector !== 'string') { @@ -64,7 +64,7 @@ export function componentNeedsCompiling(component: Component): boolean { export function isRefSelector(refOptionsObject: any): boolean { if ( !isPlainObject(refOptionsObject) || - Object.keys(refOptionsObject || {}).length !== 1 + keys(refOptionsObject || {}).length !== 1 ) { return false } @@ -137,10 +137,10 @@ function makeMap(str: string, expectsLowerCase?: boolean) { map[list[i]] = true } return expectsLowerCase - ? function(val: string) { + ? function (val: string) { return map[val.toLowerCase()] } - : function(val: string) { + : function (val: string) { return map[val] } } diff --git a/packages/test-utils/dist/vue-test-utils.esm.js b/packages/test-utils/dist/vue-test-utils.esm.js index ec5ae5f13..3761009fb 100644 --- a/packages/test-utils/dist/vue-test-utils.esm.js +++ b/packages/test-utils/dist/vue-test-utils.esm.js @@ -1810,7 +1810,7 @@ function addMocks( if (mockedProperties === false) { return } - Object.keys(mockedProperties).forEach(function (key) { + keys(mockedProperties).forEach(function (key) { try { // $FlowIgnore _Vue.prototype[key] = mockedProperties[key]; @@ -1845,7 +1845,7 @@ function logEvents( function addEventLogger(_Vue) { _Vue.mixin({ - beforeCreate: function() { + beforeCreate: function () { this.__emitted = Object.create(null); this.__emittedByOrder = []; logEvents(this, this.__emitted, this.__emittedByOrder); @@ -1897,7 +1897,7 @@ function isVueComponent(c) { return true } - if (c === null || typeof c !== 'object') { + if (!isPlainObject(c)) { return false } @@ -1927,8 +1927,8 @@ function componentNeedsCompiling(component) { function isRefSelector(refOptionsObject) { if ( - typeof refOptionsObject !== 'object' || - Object.keys(refOptionsObject || {}).length !== 1 + !isPlainObject(refOptionsObject) || + keys(refOptionsObject || {}).length !== 1 ) { return false } @@ -1937,7 +1937,7 @@ function isRefSelector(refOptionsObject) { } function isNameSelector(nameOptionsObject) { - if (typeof nameOptionsObject !== 'object' || nameOptionsObject === null) { + if (!isPlainObject(nameOptionsObject)) { return false } @@ -1953,7 +1953,7 @@ function isDynamicComponent(c) { } function isComponentOptions(c) { - return c !== null && typeof c === 'object' && (c.template || c.render) + return isPlainObject(c) && (c.template || c.render) } function isFunctionalComponent(c) { @@ -1995,10 +1995,10 @@ function makeMap(str, expectsLowerCase) { map[list[i]] = true; } return expectsLowerCase - ? function(val) { + ? function (val) { return map[val.toLowerCase()] } - : function(val) { + : function (val) { return map[val] } } @@ -2055,7 +2055,7 @@ function compileTemplate(component) { } if (component.components) { - Object.keys(component.components).forEach(function (c) { + keys(component.components).forEach(function (c) { var cmp = component.components[c]; if (!cmp.render) { compileTemplate(cmp); @@ -2073,7 +2073,7 @@ function compileTemplate(component) { } function compileTemplateForSlots(slots) { - Object.keys(slots).forEach(function (key) { + keys(slots).forEach(function (key) { var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]; slot.forEach(function (slotValue) { if (componentNeedsCompiling(slotValue)) { @@ -2113,9 +2113,7 @@ function isDestructuringSlotScope(slotScope) { return /^{.*}$/.test(slotScope) } -function getVueTemplateCompilerHelpers( - _Vue -) { +function getVueTemplateCompilerHelpers(_Vue) { // $FlowIgnore var vue = new _Vue(); var helpers = {}; @@ -2214,7 +2212,7 @@ function createScopedSlots( var slotScope = scopedSlotMatches.match && scopedSlotMatches.match[1]; - scopedSlots[scopedSlotName] = function(props) { + scopedSlots[scopedSlotName] = function (props) { var obj; var res; @@ -2263,10 +2261,10 @@ function resolveComponent$1(obj, component) { ) } -function getCoreProperties(componentOptions) { +function getCoreProperties(componentOptions, name) { return { attrs: componentOptions.attrs, - name: componentOptions.name, + name: componentOptions.name || name, model: componentOptions.model, props: componentOptions.props, on: componentOptions.on, @@ -2327,7 +2325,7 @@ function createStubFromComponent( Vue.config.ignoredElements.push(tagName); } - return Object.assign({}, getCoreProperties(componentOptions), + return Object.assign({}, getCoreProperties(componentOptions, name), {$_vueTestUtils_original: originalComponent, $_doNotStubChildren: true, render: function render(h, context) { @@ -2412,7 +2410,7 @@ function createStubsFromStubsObject( ) { if ( originalComponents === void 0 ) originalComponents = {}; - return Object.keys(stubs || {}).reduce(function (acc, stubName) { + return keys(stubs || {}).reduce(function (acc, stubName) { var stub = stubs[stubName]; validateStub(stub); @@ -2508,8 +2506,16 @@ function patchCreateElement(_Vue, stubs, stubAllComponents) { } if (isConstructor(el) || isComponentOptions(el)) { + var componentOptions = isConstructor(el) ? el.options : el; + var elName = componentOptions.name; + + var stubbedComponent = resolveComponent(elName, stubs); + if (stubbedComponent) { + return originalCreateElement.apply(void 0, [ stubbedComponent ].concat( args )) + } + if (stubAllComponents) { - var stub = createStubFromComponent(el, el.name || 'anonymous', _Vue); + var stub = createStubFromComponent(el, elName || 'anonymous', _Vue); return originalCreateElement.apply(void 0, [ stub ].concat( args )) } var Constructor = shouldExtend(el) ? extend(el, _Vue) : el; @@ -2622,8 +2628,8 @@ function createInstance( // watchers provided in mounting options should override preexisting ones if (componentOptions.watch && instanceOptions.watch) { - var componentWatchers = Object.keys(componentOptions.watch); - var instanceWatchers = Object.keys(instanceOptions.watch); + var componentWatchers = keys(componentOptions.watch); + var instanceWatchers = keys(instanceOptions.watch); for (var i = 0; i < instanceWatchers.length; i++) { var k = instanceWatchers[i]; @@ -2643,14 +2649,14 @@ function createInstance( var parentComponentOptions = options.parentComponent || {}; var originalParentComponentProvide = parentComponentOptions.provide; - parentComponentOptions.provide = function() { + parentComponentOptions.provide = function () { return Object.assign({}, getValuesFromCallableOption.call(this, originalParentComponentProvide), // $FlowIgnore getValuesFromCallableOption.call(this, options.provide)) }; var originalParentComponentData = parentComponentOptions.data; - parentComponentOptions.data = function() { + parentComponentOptions.data = function () { return Object.assign({}, getValuesFromCallableOption.call(this, originalParentComponentData), {vueTestUtils_childProps: Object.assign({}, options.propsData)}) }; @@ -2658,7 +2664,7 @@ function createInstance( parentComponentOptions.$_doNotStubChildren = true; parentComponentOptions.$_isWrapperParent = true; parentComponentOptions._isFunctionalContainer = componentOptions.functional; - parentComponentOptions.render = function(h) { + parentComponentOptions.render = function (h) { return h( Constructor, createContext(options, scopedSlots, this.vueTestUtils_childProps), @@ -2751,7 +2757,7 @@ function vmCtorMatches(vm, component) { } if (component.functional) { - return Object.keys(vm._Ctor || {}).some(function (c) { + return keys(vm._Ctor || {}).some(function (c) { return component === vm._Ctor[c].extendOptions }) } @@ -3010,7 +3016,7 @@ function getOption(option, config) { if (option === false) { return false } - if (option || (config && Object.keys(config).length > 0)) { + if (option || (config && keys(config).length > 0)) { if (option instanceof Function) { return option } @@ -3034,7 +3040,7 @@ function mergeOptions( ) { var mocks = (getOption(options.mocks, config.mocks)); var methods = (getOption(options.methods, config.methods)); - if (methods && Object.keys(methods).length) { + if (methods && keys(methods).length) { warnDeprecated( 'overwriting methods via the `methods` property', 'There is no clear migration path for the `methods` property - Vue does not support arbitrarily replacement of methods, nor should VTU. To stub a complex method extract it from the component and test it in isolation. Otherwise, the suggestion is to rethink those tests' @@ -9011,7 +9017,10 @@ ErrorWrapper.prototype.destroy = function destroy () { */ function isStyleVisible(element) { - if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) { + if ( + !(element instanceof window.HTMLElement) && + !(element instanceof window.SVGElement) + ) { return false } @@ -9051,14 +9060,14 @@ function isElementVisible(element, previousElement) { } function recursivelySetData(vm, target, data) { - Object.keys(data).forEach(function (key) { + keys(data).forEach(function (key) { var val = data[key]; var targetVal = target[key]; if ( isPlainObject(val) && isPlainObject(targetVal) && - Object.keys(val).length > 0 + keys(val).length > 0 ) { recursivelySetData(vm, targetVal, val); } else { @@ -10306,10 +10315,10 @@ var w3cKeys = { esc: 'Esc', escape: 'Escape', space: ' ', - up: 'Up', - left: 'Left', - right: 'Right', - down: 'Down', + up: 'ArrowUp', + left: 'ArrowLeft', + right: 'ArrowRight', + down: 'ArrowDown', end: 'End', home: 'Home', backspace: 'Backspace', @@ -10394,7 +10403,7 @@ function createDOMEvent(type, options) { : createOldEvent(eventParams); var eventPrototype = Object.getPrototypeOf(event); - Object.keys(options || {}).forEach(function (key) { + keys(options || {}).forEach(function (key) { var propertyDescriptor = Object.getOwnPropertyDescriptor( eventPrototype, key @@ -10500,17 +10509,14 @@ Wrapper.prototype.classes = function classes (className) { var classes = classAttribute ? classAttribute.split(' ') : []; // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { - var cssModuleIdentifiers = Object.keys(this.vm.$style).reduce( - function (acc, key) { - // $FlowIgnore - var moduleIdent = this$1.vm.$style[key]; - if (moduleIdent) { - acc[moduleIdent.split(' ')[0]] = key; - } - return acc - }, - {} - ); + var cssModuleIdentifiers = keys(this.vm.$style).reduce(function (acc, key) { + // $FlowIgnore + var moduleIdent = this$1.vm.$style[key]; + if (moduleIdent) { + acc[moduleIdent.split(' ')[0]] = key; + } + return acc + }, {}); classes = classes.map(function (name) { return cssModuleIdentifiers[name] || name; }); } @@ -10864,7 +10870,7 @@ Wrapper.prototype.overview = function overview () { var computed = this.vm._computedWatchers ? formatJSON.apply( // $FlowIgnore - void 0, Object.keys(this.vm._computedWatchers).map(function (computedKey) { + void 0, keys(this.vm._computedWatchers).map(function (computedKey) { var obj; return (( obj = {}, obj[computedKey] = this$1.vm[computedKey], obj )); @@ -10888,9 +10894,7 @@ Wrapper.prototype.overview = function overview () { var emittedJSONReplacer = function (key, value) { return value instanceof Array ? value.map(function (calledWith, index) { var callParams = calledWith.map(function (param) { return typeof param === 'object' - ? JSON.stringify(param) - .replace(/"/g, '') - .replace(/,/g, ', ') + ? JSON.stringify(param).replace(/"/g, '').replace(/,/g, ', ') : param; } ); @@ -11072,7 +11076,7 @@ Wrapper.prototype.setMethods = function setMethods (methods) { } this.__warnIfDestroyed(); - Object.keys(methods).forEach(function (key) { + keys(methods).forEach(function (key) { // $FlowIgnore : Problem with possibly null this.vm this$1.vm[key] = methods[key]; // $FlowIgnore : Problem with possibly null this.vm @@ -11111,11 +11115,10 @@ Wrapper.prototype.setProps = function setProps (data) { this.__warnIfDestroyed(); - Object.keys(data).forEach(function (key) { + keys(data).forEach(function (key) { // Don't let people set entire objects, because reactivity won't work if ( - typeof data[key] === 'object' && - data[key] !== null && + isPlainObject(data[key]) && // $FlowIgnore : Problem with possibly null this.vm data[key] === this$1.vm[key] ) { @@ -13883,7 +13886,7 @@ function _createLocalVue( var instance = _Vue.extend(); // clone global APIs - Object.keys(_Vue).forEach(function (key) { + keys(_Vue).forEach(function (key) { if (!instance.hasOwnProperty(key)) { var original = _Vue[key]; // cloneDeep can fail when cloning Vue instances @@ -13950,7 +13953,7 @@ function requiresTemplateCompiler(slot) { } function validateSlots(slots) { - Object.keys(slots).forEach(function (key) { + keys(slots).forEach(function (key) { var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]; slot.forEach(function (slotValue) { diff --git a/packages/test-utils/dist/vue-test-utils.iife.js b/packages/test-utils/dist/vue-test-utils.iife.js index d2ad58734..9be5829e2 100644 --- a/packages/test-utils/dist/vue-test-utils.iife.js +++ b/packages/test-utils/dist/vue-test-utils.iife.js @@ -1814,7 +1814,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { if (mockedProperties === false) { return } - Object.keys(mockedProperties).forEach(function (key) { + keys(mockedProperties).forEach(function (key) { try { // $FlowIgnore _Vue.prototype[key] = mockedProperties[key]; @@ -1849,7 +1849,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { function addEventLogger(_Vue) { _Vue.mixin({ - beforeCreate: function() { + beforeCreate: function () { this.__emitted = Object.create(null); this.__emittedByOrder = []; logEvents(this, this.__emitted, this.__emittedByOrder); @@ -1901,7 +1901,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { return true } - if (c === null || typeof c !== 'object') { + if (!isPlainObject(c)) { return false } @@ -1931,8 +1931,8 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { function isRefSelector(refOptionsObject) { if ( - typeof refOptionsObject !== 'object' || - Object.keys(refOptionsObject || {}).length !== 1 + !isPlainObject(refOptionsObject) || + keys(refOptionsObject || {}).length !== 1 ) { return false } @@ -1941,7 +1941,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { } function isNameSelector(nameOptionsObject) { - if (typeof nameOptionsObject !== 'object' || nameOptionsObject === null) { + if (!isPlainObject(nameOptionsObject)) { return false } @@ -1957,7 +1957,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { } function isComponentOptions(c) { - return c !== null && typeof c === 'object' && (c.template || c.render) + return isPlainObject(c) && (c.template || c.render) } function isFunctionalComponent(c) { @@ -1999,10 +1999,10 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { map[list[i]] = true; } return expectsLowerCase - ? function(val) { + ? function (val) { return map[val.toLowerCase()] } - : function(val) { + : function (val) { return map[val] } } @@ -2059,7 +2059,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { } if (component.components) { - Object.keys(component.components).forEach(function (c) { + keys(component.components).forEach(function (c) { var cmp = component.components[c]; if (!cmp.render) { compileTemplate(cmp); @@ -2077,7 +2077,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { } function compileTemplateForSlots(slots) { - Object.keys(slots).forEach(function (key) { + keys(slots).forEach(function (key) { var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]; slot.forEach(function (slotValue) { if (componentNeedsCompiling(slotValue)) { @@ -2117,9 +2117,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { return /^{.*}$/.test(slotScope) } - function getVueTemplateCompilerHelpers( - _Vue - ) { + function getVueTemplateCompilerHelpers(_Vue) { // $FlowIgnore var vue = new _Vue(); var helpers = {}; @@ -2218,7 +2216,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { var slotScope = scopedSlotMatches.match && scopedSlotMatches.match[1]; - scopedSlots[scopedSlotName] = function(props) { + scopedSlots[scopedSlotName] = function (props) { var obj; var res; @@ -2267,10 +2265,10 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { ) } - function getCoreProperties(componentOptions) { + function getCoreProperties(componentOptions, name) { return { attrs: componentOptions.attrs, - name: componentOptions.name, + name: componentOptions.name || name, model: componentOptions.model, props: componentOptions.props, on: componentOptions.on, @@ -2331,7 +2329,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { Vue__default['default'].config.ignoredElements.push(tagName); } - return Object.assign({}, getCoreProperties(componentOptions), + return Object.assign({}, getCoreProperties(componentOptions, name), {$_vueTestUtils_original: originalComponent, $_doNotStubChildren: true, render: function render(h, context) { @@ -2416,7 +2414,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { ) { if ( originalComponents === void 0 ) originalComponents = {}; - return Object.keys(stubs || {}).reduce(function (acc, stubName) { + return keys(stubs || {}).reduce(function (acc, stubName) { var stub = stubs[stubName]; validateStub(stub); @@ -2512,8 +2510,16 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { } if (isConstructor(el) || isComponentOptions(el)) { + var componentOptions = isConstructor(el) ? el.options : el; + var elName = componentOptions.name; + + var stubbedComponent = resolveComponent(elName, stubs); + if (stubbedComponent) { + return originalCreateElement.apply(void 0, [ stubbedComponent ].concat( args )) + } + if (stubAllComponents) { - var stub = createStubFromComponent(el, el.name || 'anonymous', _Vue); + var stub = createStubFromComponent(el, elName || 'anonymous', _Vue); return originalCreateElement.apply(void 0, [ stub ].concat( args )) } var Constructor = shouldExtend(el) ? extend(el, _Vue) : el; @@ -2626,8 +2632,8 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { // watchers provided in mounting options should override preexisting ones if (componentOptions.watch && instanceOptions.watch) { - var componentWatchers = Object.keys(componentOptions.watch); - var instanceWatchers = Object.keys(instanceOptions.watch); + var componentWatchers = keys(componentOptions.watch); + var instanceWatchers = keys(instanceOptions.watch); for (var i = 0; i < instanceWatchers.length; i++) { var k = instanceWatchers[i]; @@ -2647,14 +2653,14 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { var parentComponentOptions = options.parentComponent || {}; var originalParentComponentProvide = parentComponentOptions.provide; - parentComponentOptions.provide = function() { + parentComponentOptions.provide = function () { return Object.assign({}, getValuesFromCallableOption.call(this, originalParentComponentProvide), // $FlowIgnore getValuesFromCallableOption.call(this, options.provide)) }; var originalParentComponentData = parentComponentOptions.data; - parentComponentOptions.data = function() { + parentComponentOptions.data = function () { return Object.assign({}, getValuesFromCallableOption.call(this, originalParentComponentData), {vueTestUtils_childProps: Object.assign({}, options.propsData)}) }; @@ -2662,7 +2668,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { parentComponentOptions.$_doNotStubChildren = true; parentComponentOptions.$_isWrapperParent = true; parentComponentOptions._isFunctionalContainer = componentOptions.functional; - parentComponentOptions.render = function(h) { + parentComponentOptions.render = function (h) { return h( Constructor, createContext(options, scopedSlots, this.vueTestUtils_childProps), @@ -2755,7 +2761,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { } if (component.functional) { - return Object.keys(vm._Ctor || {}).some(function (c) { + return keys(vm._Ctor || {}).some(function (c) { return component === vm._Ctor[c].extendOptions }) } @@ -3014,7 +3020,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { if (option === false) { return false } - if (option || (config && Object.keys(config).length > 0)) { + if (option || (config && keys(config).length > 0)) { if (option instanceof Function) { return option } @@ -3038,7 +3044,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { ) { var mocks = (getOption(options.mocks, config.mocks)); var methods = (getOption(options.methods, config.methods)); - if (methods && Object.keys(methods).length) { + if (methods && keys(methods).length) { warnDeprecated( 'overwriting methods via the `methods` property', 'There is no clear migration path for the `methods` property - Vue does not support arbitrarily replacement of methods, nor should VTU. To stub a complex method extract it from the component and test it in isolation. Otherwise, the suggestion is to rethink those tests' @@ -9015,7 +9021,10 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { */ function isStyleVisible(element) { - if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) { + if ( + !(element instanceof window.HTMLElement) && + !(element instanceof window.SVGElement) + ) { return false } @@ -9055,14 +9064,14 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { } function recursivelySetData(vm, target, data) { - Object.keys(data).forEach(function (key) { + keys(data).forEach(function (key) { var val = data[key]; var targetVal = target[key]; if ( isPlainObject(val) && isPlainObject(targetVal) && - Object.keys(val).length > 0 + keys(val).length > 0 ) { recursivelySetData(vm, targetVal, val); } else { @@ -10310,10 +10319,10 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { esc: 'Esc', escape: 'Escape', space: ' ', - up: 'Up', - left: 'Left', - right: 'Right', - down: 'Down', + up: 'ArrowUp', + left: 'ArrowLeft', + right: 'ArrowRight', + down: 'ArrowDown', end: 'End', home: 'Home', backspace: 'Backspace', @@ -10398,7 +10407,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { : createOldEvent(eventParams); var eventPrototype = Object.getPrototypeOf(event); - Object.keys(options || {}).forEach(function (key) { + keys(options || {}).forEach(function (key) { var propertyDescriptor = Object.getOwnPropertyDescriptor( eventPrototype, key @@ -10504,17 +10513,14 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { var classes = classAttribute ? classAttribute.split(' ') : []; // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { - var cssModuleIdentifiers = Object.keys(this.vm.$style).reduce( - function (acc, key) { - // $FlowIgnore - var moduleIdent = this$1.vm.$style[key]; - if (moduleIdent) { - acc[moduleIdent.split(' ')[0]] = key; - } - return acc - }, - {} - ); + var cssModuleIdentifiers = keys(this.vm.$style).reduce(function (acc, key) { + // $FlowIgnore + var moduleIdent = this$1.vm.$style[key]; + if (moduleIdent) { + acc[moduleIdent.split(' ')[0]] = key; + } + return acc + }, {}); classes = classes.map(function (name) { return cssModuleIdentifiers[name] || name; }); } @@ -10868,7 +10874,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { var computed = this.vm._computedWatchers ? formatJSON.apply( // $FlowIgnore - void 0, Object.keys(this.vm._computedWatchers).map(function (computedKey) { + void 0, keys(this.vm._computedWatchers).map(function (computedKey) { var obj; return (( obj = {}, obj[computedKey] = this$1.vm[computedKey], obj )); @@ -10892,9 +10898,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { var emittedJSONReplacer = function (key, value) { return value instanceof Array ? value.map(function (calledWith, index) { var callParams = calledWith.map(function (param) { return typeof param === 'object' - ? JSON.stringify(param) - .replace(/"/g, '') - .replace(/,/g, ', ') + ? JSON.stringify(param).replace(/"/g, '').replace(/,/g, ', ') : param; } ); @@ -11076,7 +11080,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { } this.__warnIfDestroyed(); - Object.keys(methods).forEach(function (key) { + keys(methods).forEach(function (key) { // $FlowIgnore : Problem with possibly null this.vm this$1.vm[key] = methods[key]; // $FlowIgnore : Problem with possibly null this.vm @@ -11115,11 +11119,10 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { this.__warnIfDestroyed(); - Object.keys(data).forEach(function (key) { + keys(data).forEach(function (key) { // Don't let people set entire objects, because reactivity won't work if ( - typeof data[key] === 'object' && - data[key] !== null && + isPlainObject(data[key]) && // $FlowIgnore : Problem with possibly null this.vm data[key] === this$1.vm[key] ) { @@ -13887,7 +13890,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { var instance = _Vue.extend(); // clone global APIs - Object.keys(_Vue).forEach(function (key) { + keys(_Vue).forEach(function (key) { if (!instance.hasOwnProperty(key)) { var original = _Vue[key]; // cloneDeep can fail when cloning Vue instances @@ -13954,7 +13957,7 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { } function validateSlots(slots) { - Object.keys(slots).forEach(function (key) { + keys(slots).forEach(function (key) { var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]; slot.forEach(function (slotValue) { diff --git a/packages/test-utils/dist/vue-test-utils.js b/packages/test-utils/dist/vue-test-utils.js index c577f2e63..008baaeb1 100644 --- a/packages/test-utils/dist/vue-test-utils.js +++ b/packages/test-utils/dist/vue-test-utils.js @@ -1818,7 +1818,7 @@ function addMocks( if (mockedProperties === false) { return } - Object.keys(mockedProperties).forEach(function (key) { + keys(mockedProperties).forEach(function (key) { try { // $FlowIgnore _Vue.prototype[key] = mockedProperties[key]; @@ -1853,7 +1853,7 @@ function logEvents( function addEventLogger(_Vue) { _Vue.mixin({ - beforeCreate: function() { + beforeCreate: function () { this.__emitted = Object.create(null); this.__emittedByOrder = []; logEvents(this, this.__emitted, this.__emittedByOrder); @@ -1905,7 +1905,7 @@ function isVueComponent(c) { return true } - if (c === null || typeof c !== 'object') { + if (!isPlainObject(c)) { return false } @@ -1935,8 +1935,8 @@ function componentNeedsCompiling(component) { function isRefSelector(refOptionsObject) { if ( - typeof refOptionsObject !== 'object' || - Object.keys(refOptionsObject || {}).length !== 1 + !isPlainObject(refOptionsObject) || + keys(refOptionsObject || {}).length !== 1 ) { return false } @@ -1945,7 +1945,7 @@ function isRefSelector(refOptionsObject) { } function isNameSelector(nameOptionsObject) { - if (typeof nameOptionsObject !== 'object' || nameOptionsObject === null) { + if (!isPlainObject(nameOptionsObject)) { return false } @@ -1961,7 +1961,7 @@ function isDynamicComponent(c) { } function isComponentOptions(c) { - return c !== null && typeof c === 'object' && (c.template || c.render) + return isPlainObject(c) && (c.template || c.render) } function isFunctionalComponent(c) { @@ -2003,10 +2003,10 @@ function makeMap(str, expectsLowerCase) { map[list[i]] = true; } return expectsLowerCase - ? function(val) { + ? function (val) { return map[val.toLowerCase()] } - : function(val) { + : function (val) { return map[val] } } @@ -2063,7 +2063,7 @@ function compileTemplate(component) { } if (component.components) { - Object.keys(component.components).forEach(function (c) { + keys(component.components).forEach(function (c) { var cmp = component.components[c]; if (!cmp.render) { compileTemplate(cmp); @@ -2081,7 +2081,7 @@ function compileTemplate(component) { } function compileTemplateForSlots(slots) { - Object.keys(slots).forEach(function (key) { + keys(slots).forEach(function (key) { var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]; slot.forEach(function (slotValue) { if (componentNeedsCompiling(slotValue)) { @@ -2121,9 +2121,7 @@ function isDestructuringSlotScope(slotScope) { return /^{.*}$/.test(slotScope) } -function getVueTemplateCompilerHelpers( - _Vue -) { +function getVueTemplateCompilerHelpers(_Vue) { // $FlowIgnore var vue = new _Vue(); var helpers = {}; @@ -2222,7 +2220,7 @@ function createScopedSlots( var slotScope = scopedSlotMatches.match && scopedSlotMatches.match[1]; - scopedSlots[scopedSlotName] = function(props) { + scopedSlots[scopedSlotName] = function (props) { var obj; var res; @@ -2271,10 +2269,10 @@ function resolveComponent$1(obj, component) { ) } -function getCoreProperties(componentOptions) { +function getCoreProperties(componentOptions, name) { return { attrs: componentOptions.attrs, - name: componentOptions.name, + name: componentOptions.name || name, model: componentOptions.model, props: componentOptions.props, on: componentOptions.on, @@ -2335,7 +2333,7 @@ function createStubFromComponent( Vue__default['default'].config.ignoredElements.push(tagName); } - return Object.assign({}, getCoreProperties(componentOptions), + return Object.assign({}, getCoreProperties(componentOptions, name), {$_vueTestUtils_original: originalComponent, $_doNotStubChildren: true, render: function render(h, context) { @@ -2420,7 +2418,7 @@ function createStubsFromStubsObject( ) { if ( originalComponents === void 0 ) originalComponents = {}; - return Object.keys(stubs || {}).reduce(function (acc, stubName) { + return keys(stubs || {}).reduce(function (acc, stubName) { var stub = stubs[stubName]; validateStub(stub); @@ -2516,8 +2514,16 @@ function patchCreateElement(_Vue, stubs, stubAllComponents) { } if (isConstructor(el) || isComponentOptions(el)) { + var componentOptions = isConstructor(el) ? el.options : el; + var elName = componentOptions.name; + + var stubbedComponent = resolveComponent(elName, stubs); + if (stubbedComponent) { + return originalCreateElement.apply(void 0, [ stubbedComponent ].concat( args )) + } + if (stubAllComponents) { - var stub = createStubFromComponent(el, el.name || 'anonymous', _Vue); + var stub = createStubFromComponent(el, elName || 'anonymous', _Vue); return originalCreateElement.apply(void 0, [ stub ].concat( args )) } var Constructor = shouldExtend(el) ? extend(el, _Vue) : el; @@ -2630,8 +2636,8 @@ function createInstance( // watchers provided in mounting options should override preexisting ones if (componentOptions.watch && instanceOptions.watch) { - var componentWatchers = Object.keys(componentOptions.watch); - var instanceWatchers = Object.keys(instanceOptions.watch); + var componentWatchers = keys(componentOptions.watch); + var instanceWatchers = keys(instanceOptions.watch); for (var i = 0; i < instanceWatchers.length; i++) { var k = instanceWatchers[i]; @@ -2651,14 +2657,14 @@ function createInstance( var parentComponentOptions = options.parentComponent || {}; var originalParentComponentProvide = parentComponentOptions.provide; - parentComponentOptions.provide = function() { + parentComponentOptions.provide = function () { return Object.assign({}, getValuesFromCallableOption.call(this, originalParentComponentProvide), // $FlowIgnore getValuesFromCallableOption.call(this, options.provide)) }; var originalParentComponentData = parentComponentOptions.data; - parentComponentOptions.data = function() { + parentComponentOptions.data = function () { return Object.assign({}, getValuesFromCallableOption.call(this, originalParentComponentData), {vueTestUtils_childProps: Object.assign({}, options.propsData)}) }; @@ -2666,7 +2672,7 @@ function createInstance( parentComponentOptions.$_doNotStubChildren = true; parentComponentOptions.$_isWrapperParent = true; parentComponentOptions._isFunctionalContainer = componentOptions.functional; - parentComponentOptions.render = function(h) { + parentComponentOptions.render = function (h) { return h( Constructor, createContext(options, scopedSlots, this.vueTestUtils_childProps), @@ -2759,7 +2765,7 @@ function vmCtorMatches(vm, component) { } if (component.functional) { - return Object.keys(vm._Ctor || {}).some(function (c) { + return keys(vm._Ctor || {}).some(function (c) { return component === vm._Ctor[c].extendOptions }) } @@ -3018,7 +3024,7 @@ function getOption(option, config) { if (option === false) { return false } - if (option || (config && Object.keys(config).length > 0)) { + if (option || (config && keys(config).length > 0)) { if (option instanceof Function) { return option } @@ -3042,7 +3048,7 @@ function mergeOptions( ) { var mocks = (getOption(options.mocks, config.mocks)); var methods = (getOption(options.methods, config.methods)); - if (methods && Object.keys(methods).length) { + if (methods && keys(methods).length) { warnDeprecated( 'overwriting methods via the `methods` property', 'There is no clear migration path for the `methods` property - Vue does not support arbitrarily replacement of methods, nor should VTU. To stub a complex method extract it from the component and test it in isolation. Otherwise, the suggestion is to rethink those tests' @@ -9019,7 +9025,10 @@ ErrorWrapper.prototype.destroy = function destroy () { */ function isStyleVisible(element) { - if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) { + if ( + !(element instanceof window.HTMLElement) && + !(element instanceof window.SVGElement) + ) { return false } @@ -9059,14 +9068,14 @@ function isElementVisible(element, previousElement) { } function recursivelySetData(vm, target, data) { - Object.keys(data).forEach(function (key) { + keys(data).forEach(function (key) { var val = data[key]; var targetVal = target[key]; if ( isPlainObject(val) && isPlainObject(targetVal) && - Object.keys(val).length > 0 + keys(val).length > 0 ) { recursivelySetData(vm, targetVal, val); } else { @@ -10314,10 +10323,10 @@ var w3cKeys = { esc: 'Esc', escape: 'Escape', space: ' ', - up: 'Up', - left: 'Left', - right: 'Right', - down: 'Down', + up: 'ArrowUp', + left: 'ArrowLeft', + right: 'ArrowRight', + down: 'ArrowDown', end: 'End', home: 'Home', backspace: 'Backspace', @@ -10402,7 +10411,7 @@ function createDOMEvent(type, options) { : createOldEvent(eventParams); var eventPrototype = Object.getPrototypeOf(event); - Object.keys(options || {}).forEach(function (key) { + keys(options || {}).forEach(function (key) { var propertyDescriptor = Object.getOwnPropertyDescriptor( eventPrototype, key @@ -10508,17 +10517,14 @@ Wrapper.prototype.classes = function classes (className) { var classes = classAttribute ? classAttribute.split(' ') : []; // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { - var cssModuleIdentifiers = Object.keys(this.vm.$style).reduce( - function (acc, key) { - // $FlowIgnore - var moduleIdent = this$1.vm.$style[key]; - if (moduleIdent) { - acc[moduleIdent.split(' ')[0]] = key; - } - return acc - }, - {} - ); + var cssModuleIdentifiers = keys(this.vm.$style).reduce(function (acc, key) { + // $FlowIgnore + var moduleIdent = this$1.vm.$style[key]; + if (moduleIdent) { + acc[moduleIdent.split(' ')[0]] = key; + } + return acc + }, {}); classes = classes.map(function (name) { return cssModuleIdentifiers[name] || name; }); } @@ -10872,7 +10878,7 @@ Wrapper.prototype.overview = function overview () { var computed = this.vm._computedWatchers ? formatJSON.apply( // $FlowIgnore - void 0, Object.keys(this.vm._computedWatchers).map(function (computedKey) { + void 0, keys(this.vm._computedWatchers).map(function (computedKey) { var obj; return (( obj = {}, obj[computedKey] = this$1.vm[computedKey], obj )); @@ -10896,9 +10902,7 @@ Wrapper.prototype.overview = function overview () { var emittedJSONReplacer = function (key, value) { return value instanceof Array ? value.map(function (calledWith, index) { var callParams = calledWith.map(function (param) { return typeof param === 'object' - ? JSON.stringify(param) - .replace(/"/g, '') - .replace(/,/g, ', ') + ? JSON.stringify(param).replace(/"/g, '').replace(/,/g, ', ') : param; } ); @@ -11080,7 +11084,7 @@ Wrapper.prototype.setMethods = function setMethods (methods) { } this.__warnIfDestroyed(); - Object.keys(methods).forEach(function (key) { + keys(methods).forEach(function (key) { // $FlowIgnore : Problem with possibly null this.vm this$1.vm[key] = methods[key]; // $FlowIgnore : Problem with possibly null this.vm @@ -11119,11 +11123,10 @@ Wrapper.prototype.setProps = function setProps (data) { this.__warnIfDestroyed(); - Object.keys(data).forEach(function (key) { + keys(data).forEach(function (key) { // Don't let people set entire objects, because reactivity won't work if ( - typeof data[key] === 'object' && - data[key] !== null && + isPlainObject(data[key]) && // $FlowIgnore : Problem with possibly null this.vm data[key] === this$1.vm[key] ) { @@ -13891,7 +13894,7 @@ function _createLocalVue( var instance = _Vue.extend(); // clone global APIs - Object.keys(_Vue).forEach(function (key) { + keys(_Vue).forEach(function (key) { if (!instance.hasOwnProperty(key)) { var original = _Vue[key]; // cloneDeep can fail when cloning Vue instances @@ -13958,7 +13961,7 @@ function requiresTemplateCompiler(slot) { } function validateSlots(slots) { - Object.keys(slots).forEach(function (key) { + keys(slots).forEach(function (key) { var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]; slot.forEach(function (slotValue) { diff --git a/packages/test-utils/dist/vue-test-utils.umd.js b/packages/test-utils/dist/vue-test-utils.umd.js index 23eae2145..4f9afe3e5 100644 --- a/packages/test-utils/dist/vue-test-utils.umd.js +++ b/packages/test-utils/dist/vue-test-utils.umd.js @@ -1817,7 +1817,7 @@ if (mockedProperties === false) { return } - Object.keys(mockedProperties).forEach(function (key) { + keys(mockedProperties).forEach(function (key) { try { // $FlowIgnore _Vue.prototype[key] = mockedProperties[key]; @@ -1852,7 +1852,7 @@ function addEventLogger(_Vue) { _Vue.mixin({ - beforeCreate: function() { + beforeCreate: function () { this.__emitted = Object.create(null); this.__emittedByOrder = []; logEvents(this, this.__emitted, this.__emittedByOrder); @@ -1904,7 +1904,7 @@ return true } - if (c === null || typeof c !== 'object') { + if (!isPlainObject(c)) { return false } @@ -1934,8 +1934,8 @@ function isRefSelector(refOptionsObject) { if ( - typeof refOptionsObject !== 'object' || - Object.keys(refOptionsObject || {}).length !== 1 + !isPlainObject(refOptionsObject) || + keys(refOptionsObject || {}).length !== 1 ) { return false } @@ -1944,7 +1944,7 @@ } function isNameSelector(nameOptionsObject) { - if (typeof nameOptionsObject !== 'object' || nameOptionsObject === null) { + if (!isPlainObject(nameOptionsObject)) { return false } @@ -1960,7 +1960,7 @@ } function isComponentOptions(c) { - return c !== null && typeof c === 'object' && (c.template || c.render) + return isPlainObject(c) && (c.template || c.render) } function isFunctionalComponent(c) { @@ -2002,10 +2002,10 @@ map[list[i]] = true; } return expectsLowerCase - ? function(val) { + ? function (val) { return map[val.toLowerCase()] } - : function(val) { + : function (val) { return map[val] } } @@ -2062,7 +2062,7 @@ } if (component.components) { - Object.keys(component.components).forEach(function (c) { + keys(component.components).forEach(function (c) { var cmp = component.components[c]; if (!cmp.render) { compileTemplate(cmp); @@ -2080,7 +2080,7 @@ } function compileTemplateForSlots(slots) { - Object.keys(slots).forEach(function (key) { + keys(slots).forEach(function (key) { var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]; slot.forEach(function (slotValue) { if (componentNeedsCompiling(slotValue)) { @@ -2120,9 +2120,7 @@ return /^{.*}$/.test(slotScope) } - function getVueTemplateCompilerHelpers( - _Vue - ) { + function getVueTemplateCompilerHelpers(_Vue) { // $FlowIgnore var vue = new _Vue(); var helpers = {}; @@ -2221,7 +2219,7 @@ var slotScope = scopedSlotMatches.match && scopedSlotMatches.match[1]; - scopedSlots[scopedSlotName] = function(props) { + scopedSlots[scopedSlotName] = function (props) { var obj; var res; @@ -2270,10 +2268,10 @@ ) } - function getCoreProperties(componentOptions) { + function getCoreProperties(componentOptions, name) { return { attrs: componentOptions.attrs, - name: componentOptions.name, + name: componentOptions.name || name, model: componentOptions.model, props: componentOptions.props, on: componentOptions.on, @@ -2334,7 +2332,7 @@ Vue__default['default'].config.ignoredElements.push(tagName); } - return Object.assign({}, getCoreProperties(componentOptions), + return Object.assign({}, getCoreProperties(componentOptions, name), {$_vueTestUtils_original: originalComponent, $_doNotStubChildren: true, render: function render(h, context) { @@ -2419,7 +2417,7 @@ ) { if ( originalComponents === void 0 ) originalComponents = {}; - return Object.keys(stubs || {}).reduce(function (acc, stubName) { + return keys(stubs || {}).reduce(function (acc, stubName) { var stub = stubs[stubName]; validateStub(stub); @@ -2515,8 +2513,16 @@ } if (isConstructor(el) || isComponentOptions(el)) { + var componentOptions = isConstructor(el) ? el.options : el; + var elName = componentOptions.name; + + var stubbedComponent = resolveComponent(elName, stubs); + if (stubbedComponent) { + return originalCreateElement.apply(void 0, [ stubbedComponent ].concat( args )) + } + if (stubAllComponents) { - var stub = createStubFromComponent(el, el.name || 'anonymous', _Vue); + var stub = createStubFromComponent(el, elName || 'anonymous', _Vue); return originalCreateElement.apply(void 0, [ stub ].concat( args )) } var Constructor = shouldExtend(el) ? extend(el, _Vue) : el; @@ -2629,8 +2635,8 @@ // watchers provided in mounting options should override preexisting ones if (componentOptions.watch && instanceOptions.watch) { - var componentWatchers = Object.keys(componentOptions.watch); - var instanceWatchers = Object.keys(instanceOptions.watch); + var componentWatchers = keys(componentOptions.watch); + var instanceWatchers = keys(instanceOptions.watch); for (var i = 0; i < instanceWatchers.length; i++) { var k = instanceWatchers[i]; @@ -2650,14 +2656,14 @@ var parentComponentOptions = options.parentComponent || {}; var originalParentComponentProvide = parentComponentOptions.provide; - parentComponentOptions.provide = function() { + parentComponentOptions.provide = function () { return Object.assign({}, getValuesFromCallableOption.call(this, originalParentComponentProvide), // $FlowIgnore getValuesFromCallableOption.call(this, options.provide)) }; var originalParentComponentData = parentComponentOptions.data; - parentComponentOptions.data = function() { + parentComponentOptions.data = function () { return Object.assign({}, getValuesFromCallableOption.call(this, originalParentComponentData), {vueTestUtils_childProps: Object.assign({}, options.propsData)}) }; @@ -2665,7 +2671,7 @@ parentComponentOptions.$_doNotStubChildren = true; parentComponentOptions.$_isWrapperParent = true; parentComponentOptions._isFunctionalContainer = componentOptions.functional; - parentComponentOptions.render = function(h) { + parentComponentOptions.render = function (h) { return h( Constructor, createContext(options, scopedSlots, this.vueTestUtils_childProps), @@ -2758,7 +2764,7 @@ } if (component.functional) { - return Object.keys(vm._Ctor || {}).some(function (c) { + return keys(vm._Ctor || {}).some(function (c) { return component === vm._Ctor[c].extendOptions }) } @@ -3017,7 +3023,7 @@ if (option === false) { return false } - if (option || (config && Object.keys(config).length > 0)) { + if (option || (config && keys(config).length > 0)) { if (option instanceof Function) { return option } @@ -3041,7 +3047,7 @@ ) { var mocks = (getOption(options.mocks, config.mocks)); var methods = (getOption(options.methods, config.methods)); - if (methods && Object.keys(methods).length) { + if (methods && keys(methods).length) { warnDeprecated( 'overwriting methods via the `methods` property', 'There is no clear migration path for the `methods` property - Vue does not support arbitrarily replacement of methods, nor should VTU. To stub a complex method extract it from the component and test it in isolation. Otherwise, the suggestion is to rethink those tests' @@ -9018,7 +9024,10 @@ */ function isStyleVisible(element) { - if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) { + if ( + !(element instanceof window.HTMLElement) && + !(element instanceof window.SVGElement) + ) { return false } @@ -9058,14 +9067,14 @@ } function recursivelySetData(vm, target, data) { - Object.keys(data).forEach(function (key) { + keys(data).forEach(function (key) { var val = data[key]; var targetVal = target[key]; if ( isPlainObject(val) && isPlainObject(targetVal) && - Object.keys(val).length > 0 + keys(val).length > 0 ) { recursivelySetData(vm, targetVal, val); } else { @@ -10313,10 +10322,10 @@ esc: 'Esc', escape: 'Escape', space: ' ', - up: 'Up', - left: 'Left', - right: 'Right', - down: 'Down', + up: 'ArrowUp', + left: 'ArrowLeft', + right: 'ArrowRight', + down: 'ArrowDown', end: 'End', home: 'Home', backspace: 'Backspace', @@ -10401,7 +10410,7 @@ : createOldEvent(eventParams); var eventPrototype = Object.getPrototypeOf(event); - Object.keys(options || {}).forEach(function (key) { + keys(options || {}).forEach(function (key) { var propertyDescriptor = Object.getOwnPropertyDescriptor( eventPrototype, key @@ -10507,17 +10516,14 @@ var classes = classAttribute ? classAttribute.split(' ') : []; // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { - var cssModuleIdentifiers = Object.keys(this.vm.$style).reduce( - function (acc, key) { - // $FlowIgnore - var moduleIdent = this$1.vm.$style[key]; - if (moduleIdent) { - acc[moduleIdent.split(' ')[0]] = key; - } - return acc - }, - {} - ); + var cssModuleIdentifiers = keys(this.vm.$style).reduce(function (acc, key) { + // $FlowIgnore + var moduleIdent = this$1.vm.$style[key]; + if (moduleIdent) { + acc[moduleIdent.split(' ')[0]] = key; + } + return acc + }, {}); classes = classes.map(function (name) { return cssModuleIdentifiers[name] || name; }); } @@ -10871,7 +10877,7 @@ var computed = this.vm._computedWatchers ? formatJSON.apply( // $FlowIgnore - void 0, Object.keys(this.vm._computedWatchers).map(function (computedKey) { + void 0, keys(this.vm._computedWatchers).map(function (computedKey) { var obj; return (( obj = {}, obj[computedKey] = this$1.vm[computedKey], obj )); @@ -10895,9 +10901,7 @@ var emittedJSONReplacer = function (key, value) { return value instanceof Array ? value.map(function (calledWith, index) { var callParams = calledWith.map(function (param) { return typeof param === 'object' - ? JSON.stringify(param) - .replace(/"/g, '') - .replace(/,/g, ', ') + ? JSON.stringify(param).replace(/"/g, '').replace(/,/g, ', ') : param; } ); @@ -11079,7 +11083,7 @@ } this.__warnIfDestroyed(); - Object.keys(methods).forEach(function (key) { + keys(methods).forEach(function (key) { // $FlowIgnore : Problem with possibly null this.vm this$1.vm[key] = methods[key]; // $FlowIgnore : Problem with possibly null this.vm @@ -11118,11 +11122,10 @@ this.__warnIfDestroyed(); - Object.keys(data).forEach(function (key) { + keys(data).forEach(function (key) { // Don't let people set entire objects, because reactivity won't work if ( - typeof data[key] === 'object' && - data[key] !== null && + isPlainObject(data[key]) && // $FlowIgnore : Problem with possibly null this.vm data[key] === this$1.vm[key] ) { @@ -13890,7 +13893,7 @@ var instance = _Vue.extend(); // clone global APIs - Object.keys(_Vue).forEach(function (key) { + keys(_Vue).forEach(function (key) { if (!instance.hasOwnProperty(key)) { var original = _Vue[key]; // cloneDeep can fail when cloning Vue instances @@ -13957,7 +13960,7 @@ } function validateSlots(slots) { - Object.keys(slots).forEach(function (key) { + keys(slots).forEach(function (key) { var slot = Array.isArray(slots[key]) ? slots[key] : [slots[key]]; slot.forEach(function (slotValue) { diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 16903686b..4831c0dd3 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -1,11 +1,12 @@ { "name": "@vue/test-utils", - "version": "1.3.3", + "version": "1.3.5", "description": "Utilities for testing Vue components.", "main": "dist/vue-test-utils.js", "module": "dist/vue-test-utils.esm.js", "exports": { ".": { + "types": "./types/index.d.ts", "require": "./dist/vue-test-utils.js", "import": "./dist/vue-test-utils.esm.js", "default": "./dist/vue-test-utils.js" diff --git a/packages/test-utils/src/create-dom-event.js b/packages/test-utils/src/create-dom-event.js index 47632ff1e..262076cdc 100644 --- a/packages/test-utils/src/create-dom-event.js +++ b/packages/test-utils/src/create-dom-event.js @@ -1,4 +1,5 @@ import eventTypes from 'dom-event-types' +import { keys } from 'shared/util' const defaultEventType = { eventInterface: 'Event', @@ -32,10 +33,10 @@ const w3cKeys = { esc: 'Esc', escape: 'Escape', space: ' ', - up: 'Up', - left: 'Left', - right: 'Right', - down: 'Down', + up: 'ArrowUp', + left: 'ArrowLeft', + right: 'ArrowRight', + down: 'ArrowDown', end: 'End', home: 'Home', backspace: 'Backspace', @@ -108,7 +109,7 @@ export default function createDOMEvent(type, options) { : createOldEvent(eventParams) const eventPrototype = Object.getPrototypeOf(event) - Object.keys(options || {}).forEach(key => { + keys(options || {}).forEach(key => { const propertyDescriptor = Object.getOwnPropertyDescriptor( eventPrototype, key diff --git a/packages/test-utils/src/matches.js b/packages/test-utils/src/matches.js index 6acba7661..7a51885f4 100644 --- a/packages/test-utils/src/matches.js +++ b/packages/test-utils/src/matches.js @@ -4,7 +4,7 @@ import { FUNCTIONAL_OPTIONS } from 'shared/consts' import { isConstructor, isFunctionalComponent } from 'shared/validators' -import { capitalize, camelize } from 'shared/util' +import { capitalize, camelize, keys } from 'shared/util' function vmMatchesName(vm, name) { // We want to mirror how Vue resolves component names in SFCs: @@ -48,7 +48,7 @@ function vmCtorMatches(vm, component) { } if (component.functional) { - return Object.keys(vm._Ctor || {}).some(c => { + return keys(vm._Ctor || {}).some(c => { return component === vm._Ctor[c].extendOptions }) } diff --git a/packages/test-utils/src/recursively-set-data.js b/packages/test-utils/src/recursively-set-data.js index 99cf741e2..48e3dc66a 100644 --- a/packages/test-utils/src/recursively-set-data.js +++ b/packages/test-utils/src/recursively-set-data.js @@ -1,14 +1,15 @@ import { isPlainObject } from 'shared/validators' +import { keys } from 'shared/util' export function recursivelySetData(vm, target, data) { - Object.keys(data).forEach(key => { + keys(data).forEach(key => { const val = data[key] const targetVal = target[key] if ( isPlainObject(val) && isPlainObject(targetVal) && - Object.keys(val).length > 0 + keys(val).length > 0 ) { recursivelySetData(vm, targetVal, val) } else { diff --git a/packages/test-utils/src/wrapper-array.js b/packages/test-utils/src/wrapper-array.js index f5bd64bf7..e29cb2bed 100644 --- a/packages/test-utils/src/wrapper-array.js +++ b/packages/test-utils/src/wrapper-array.js @@ -5,7 +5,7 @@ import type VueWrapper from './vue-wrapper' import { throwError } from 'shared/util' export default class WrapperArray implements BaseWrapper { - +wrappers: Array + +wrappers: Array; +length: number selector: Selector | void diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js index bbaae815a..45525008e 100644 --- a/packages/test-utils/src/wrapper.js +++ b/packages/test-utils/src/wrapper.js @@ -17,7 +17,8 @@ import { nextTick, warn, warnDeprecated, - isVueWrapper + isVueWrapper, + keys } from 'shared/util' import { isPlainObject } from 'shared/validators' import { isElementVisible } from 'shared/is-visible' @@ -29,11 +30,11 @@ import createDOMEvent from './create-dom-event' import { throwIfInstancesThrew } from './error' export default class Wrapper implements BaseWrapper { - +vnode: VNode | null + +vnode: VNode | null; +vm: Component | void _emitted: { [name: string]: Array> } - _emittedByOrder: Array<{ name: string, args: Array }> - +element: Element + _emittedByOrder: Array<{ name: string, args: Array }>; + +element: Element; +options: WrapperOptions isFunctionalComponent: boolean rootNode: VNode | Element @@ -124,17 +125,14 @@ export default class Wrapper implements BaseWrapper { let classes = classAttribute ? classAttribute.split(' ') : [] // Handle converting cssmodules identifiers back to the original class name if (this.vm && this.vm.$style) { - const cssModuleIdentifiers = Object.keys(this.vm.$style).reduce( - (acc, key) => { - // $FlowIgnore - const moduleIdent = this.vm.$style[key] - if (moduleIdent) { - acc[moduleIdent.split(' ')[0]] = key - } - return acc - }, - {} - ) + const cssModuleIdentifiers = keys(this.vm.$style).reduce((acc, key) => { + // $FlowIgnore + const moduleIdent = this.vm.$style[key] + if (moduleIdent) { + acc[moduleIdent.split(' ')[0]] = key + } + return acc + }, {}) classes = classes.map(name => cssModuleIdentifiers[name] || name) } @@ -480,7 +478,7 @@ export default class Wrapper implements BaseWrapper { const computed = this.vm._computedWatchers ? formatJSON( // $FlowIgnore - ...Object.keys(this.vm._computedWatchers).map(computedKey => ({ + ...keys(this.vm._computedWatchers).map(computedKey => ({ // $FlowIgnore [computedKey]: this.vm[computedKey] })) @@ -502,9 +500,7 @@ export default class Wrapper implements BaseWrapper { ? value.map((calledWith, index) => { const callParams = calledWith.map(param => typeof param === 'object' - ? JSON.stringify(param) - .replace(/"/g, '') - .replace(/,/g, ', ') + ? JSON.stringify(param).replace(/"/g, '').replace(/,/g, ', ') : param ) @@ -680,7 +676,7 @@ export default class Wrapper implements BaseWrapper { } this.__warnIfDestroyed() - Object.keys(methods).forEach(key => { + keys(methods).forEach(key => { // $FlowIgnore : Problem with possibly null this.vm this.vm[key] = methods[key] // $FlowIgnore : Problem with possibly null this.vm @@ -717,7 +713,7 @@ export default class Wrapper implements BaseWrapper { this.__warnIfDestroyed() - Object.keys(data).forEach(key => { + keys(data).forEach(key => { // Don't let people set entire objects, because reactivity won't work if ( isPlainObject(data[key]) && diff --git a/test/resources/components/component-with-computed.vue b/test/resources/components/component-with-computed.vue index 02445747a..d608e4885 100644 --- a/test/resources/components/component-with-computed.vue +++ b/test/resources/components/component-with-computed.vue @@ -11,11 +11,8 @@ export default { message: 'egassem' }), computed: { - reversedMessage: function() { - return this.message - .split('') - .reverse() - .join('') + reversedMessage: function () { + return this.message.split('').reverse().join('') } } } diff --git a/test/resources/components/component-with-transitions.vue b/test/resources/components/component-with-transitions.vue index 9af326ce4..e8965da44 100644 --- a/test/resources/components/component-with-transitions.vue +++ b/test/resources/components/component-with-transitions.vue @@ -1,9 +1,7 @@ diff --git a/test/resources/components/component-with-watch-immediate.vue b/test/resources/components/component-with-watch-immediate.vue index f8abce285..736be6939 100644 --- a/test/resources/components/component-with-watch-immediate.vue +++ b/test/resources/components/component-with-watch-immediate.vue @@ -6,7 +6,7 @@