vue-test-utils
Advanced tools
Comparing version 1.0.0-beta.6 to 1.0.0-beta.7
@@ -276,9 +276,8 @@ 'use strict'; | ||
function findAllVueComponents (vm, components) { | ||
function findAllVueComponentsFromVm (vm, components) { | ||
if ( components === void 0 ) components = []; | ||
components.push(vm); | ||
vm.$children.forEach(function (child) { | ||
findAllVueComponents(child, components); | ||
findAllVueComponentsFromVm(child, components); | ||
}); | ||
@@ -289,2 +288,18 @@ | ||
function findAllVueComponentsFromVnode (vnode, components) { | ||
if ( components === void 0 ) components = []; | ||
debugger | ||
if (vnode.child) { | ||
components.push(vnode.child); | ||
} | ||
if (vnode.children) { | ||
vnode.children.forEach(function (child) { | ||
findAllVueComponentsFromVnode(child, components); | ||
}); | ||
} | ||
return components | ||
} | ||
function vmCtorMatchesName (vm, name) { | ||
@@ -296,4 +311,5 @@ return (vm.$vnode && vm.$vnode.componentOptions && vm.$vnode.componentOptions.Ctor.options.name === name) || | ||
function findVueComponents (vm, componentName) { | ||
var components = findAllVueComponents(vm); | ||
function findVueComponents (root, componentName) { | ||
debugger | ||
var components = root._isVue ? findAllVueComponentsFromVm(root) : findAllVueComponentsFromVnode(root); | ||
return components.filter(function (component) { | ||
@@ -397,4 +413,5 @@ if (!component.$vnode) { | ||
}; | ||
WrapperArray.prototype.exists = function exists () { | ||
return this.wrappers.length > 0 | ||
return this.length > 0 && this.wrappers.every(function (wrapper) { return wrapper.exists(); }) | ||
}; | ||
@@ -755,2 +772,5 @@ | ||
Wrapper.prototype.exists = function exists () { | ||
if (this.isVueComponent) { | ||
return !!this.vm && !this.vm._isDestroyed | ||
} | ||
return true | ||
@@ -858,3 +878,2 @@ }; | ||
var selectorType = getSelectorTypeOrThrow(selector, 'find'); | ||
if (selectorType === selectorTypes.VUE_COMPONENT) { | ||
@@ -864,4 +883,4 @@ if (!selector.name) { | ||
} | ||
var vm = this.vm || this.vnode.context.$root; | ||
var components = findVueComponents(vm, selector.name); | ||
var root = this.vm || this.vnode; | ||
var components = findVueComponents(root, selector.name); | ||
if (components.length === 0) { | ||
@@ -904,4 +923,4 @@ return new ErrorWrapper('Component') | ||
} | ||
var vm = this.vm || this.vnode.context.$root; | ||
var components = findVueComponents(vm, selector.name); | ||
var root = this.vm || this.vnode; | ||
var components = findVueComponents(root, selector.name); | ||
return new WrapperArray(components.map(function (component) { return new VueWrapper(component, this$1.options); })) | ||
@@ -1059,2 +1078,6 @@ } | ||
} | ||
// $FlowIgnore | ||
this$1.vm._watchers.forEach(function (watcher) { | ||
if (watcher.expression === key) { watcher.run(); } | ||
}); | ||
}); | ||
@@ -1162,3 +1185,9 @@ this.update(); | ||
left: 37, | ||
right: 39 | ||
right: 39, | ||
end: 35, | ||
home: 36, | ||
backspace: 8, | ||
insert: 45, | ||
pageup: 33, | ||
pagedown: 34 | ||
}; | ||
@@ -1168,7 +1197,15 @@ | ||
var eventObject = new window.Event(event[0], { | ||
bubbles: true, | ||
cancelable: true | ||
}); | ||
var eventObject; | ||
// Fallback for IE10,11 - https://stackoverflow.com/questions/26596123 | ||
if (typeof (window.Event) === 'function') { | ||
eventObject = new window.Event(event[0], { | ||
bubbles: true, | ||
cancelable: true | ||
}); | ||
} else { | ||
eventObject = document.createEvent('Event'); | ||
eventObject.initEvent(event[0], true, true); | ||
} | ||
if (options && options.preventDefault) { | ||
@@ -1180,2 +1217,3 @@ eventObject.preventDefault(); | ||
Object.keys(options).forEach(function (key) { | ||
// $FlowIgnore | ||
eventObject[key] = options[key]; | ||
@@ -1186,2 +1224,3 @@ }); | ||
if (event.length === 2) { | ||
// $FlowIgnore | ||
eventObject.keyCode = modifiers[event[1]]; | ||
@@ -1194,14 +1233,2 @@ } | ||
function logEvents (vm, emitted, emittedByOrder) { | ||
var emit = vm.$emit; | ||
vm.$emit = function (name) { | ||
var args = [], len = arguments.length - 1; | ||
while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; | ||
(emitted[name] || (emitted[name] = [])).push(args); | ||
emittedByOrder.push({ name: name, args: args }); | ||
return emit.call.apply(emit, [ vm, name ].concat( args )) | ||
}; | ||
} | ||
// | ||
@@ -1230,6 +1257,4 @@ | ||
this.isVueComponent = true; | ||
this._emitted = Object.create(null); | ||
this._emittedByOrder = []; | ||
logEvents(vm, this._emitted, this._emittedByOrder); | ||
this._emitted = vm.__emitted; | ||
this._emittedByOrder = vm.__emittedByOrder; | ||
} | ||
@@ -1246,3 +1271,3 @@ | ||
function isValidSlot$1 (slot) { | ||
function isValidSlot (slot) { | ||
return Array.isArray(slot) || (slot !== null && typeof slot === 'object') || typeof slot === 'string' | ||
@@ -1252,21 +1277,25 @@ } | ||
function addSlotToVm (vm, slotName, slotValue) { | ||
if (Array.isArray(vm.$slots[slotName])) { | ||
if (typeof slotValue === 'string') { | ||
if (!vueTemplateCompiler.compileToFunctions) { | ||
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined'); | ||
var elem; | ||
var vueVersion = Number(((Vue.version.split('.')[0]) + "." + (Vue.version.split('.')[1]))); | ||
if (typeof slotValue === 'string') { | ||
if (!vueTemplateCompiler.compileToFunctions) { | ||
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined'); | ||
} | ||
if (slotValue.trim()[0] === '<') { | ||
elem = vm.$createElement(vueTemplateCompiler.compileToFunctions(slotValue)); | ||
} else { | ||
if (vueVersion >= 2.2) { | ||
elem = vm._v(slotValue); | ||
} else { | ||
throwError('vue-test-utils support for passing text to slots at vue@2.2+'); | ||
} | ||
vm.$slots[slotName].push(vm.$createElement(vueTemplateCompiler.compileToFunctions(slotValue))); | ||
} else { | ||
vm.$slots[slotName].push(vm.$createElement(slotValue)); | ||
} | ||
} else { | ||
if (typeof slotValue === 'string') { | ||
if (!vueTemplateCompiler.compileToFunctions) { | ||
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined'); | ||
} | ||
vm.$slots[slotName] = [vm.$createElement(vueTemplateCompiler.compileToFunctions(slotValue))]; | ||
} else { | ||
vm.$slots[slotName] = [vm.$createElement(slotValue)]; // eslint-disable-line no-param-reassign | ||
} | ||
elem = vm.$createElement(slotValue); | ||
} | ||
if (Array.isArray(vm.$slots[slotName])) { | ||
vm.$slots[slotName].push(elem); | ||
} else { | ||
vm.$slots[slotName] = [elem]; | ||
} | ||
} | ||
@@ -1276,3 +1305,3 @@ | ||
Object.keys(slots).forEach(function (key) { | ||
if (!isValidSlot$1(slots[key])) { | ||
if (!isValidSlot(slots[key])) { | ||
throwError('slots[key] must be a Component, string or an array of Components'); | ||
@@ -1335,2 +1364,26 @@ } | ||
function logEvents (vm, emitted, emittedByOrder) { | ||
var emit = vm.$emit; | ||
vm.$emit = function (name) { | ||
var args = [], len = arguments.length - 1; | ||
while ( len-- > 0 ) args[ len ] = arguments[ len + 1 ]; | ||
(emitted[name] || (emitted[name] = [])).push(args); | ||
emittedByOrder.push({ name: name, args: args }); | ||
return emit.call.apply(emit, [ vm, name ].concat( args )) | ||
}; | ||
} | ||
function addEventLogger (vue) { | ||
vue.mixin({ | ||
beforeCreate: function () { | ||
this.__emitted = Object.create(null); | ||
this.__emittedByOrder = []; | ||
logEvents(this, this.__emitted, this.__emittedByOrder); | ||
} | ||
}); | ||
} | ||
// | ||
function compileTemplate (component) { | ||
@@ -1570,3 +1623,3 @@ Object.assign(component, vueTemplateCompiler.compileToFunctions(component.template)); | ||
function isValidSlot (slot) { | ||
function isValidSlot$1 (slot) { | ||
return Array.isArray(slot) || (slot !== null && typeof slot === 'object') || typeof slot === 'string' | ||
@@ -1589,3 +1642,3 @@ } | ||
slots[slotType].forEach(function (slot) { | ||
if (!isValidSlot(slot)) { | ||
if (!isValidSlot$1(slot)) { | ||
throwError('slots[key] must be a Component, string or an array of Components'); | ||
@@ -1599,3 +1652,3 @@ } | ||
} else { | ||
if (!isValidSlot(slots[slotType])) { | ||
if (!isValidSlot$1(slots[slotType])) { | ||
throwError('slots[key] must be a Component, string or an array of Components'); | ||
@@ -1612,2 +1665,21 @@ } | ||
function createFunctionalComponent (component, mountingOptions) { | ||
if (mountingOptions.context && typeof mountingOptions.context !== 'object') { | ||
throwError('mount.context must be an object'); | ||
} | ||
var clonedComponent = cloneDeep(component); | ||
return { | ||
render: function render (h) { | ||
return h( | ||
clonedComponent, | ||
mountingOptions.context || component.FunctionalRenderContext, | ||
(mountingOptions.context && mountingOptions.context.children && mountingOptions.context.children.map(function (x) { return typeof x === 'function' ? x(h) : x; })) || createFunctionalSlots(mountingOptions.slots, h) | ||
) | ||
} | ||
} | ||
} | ||
// | ||
function createConstructor ( | ||
@@ -1626,16 +1698,3 @@ component, | ||
if (component.functional) { | ||
if (mountingOptions.context && typeof mountingOptions.context !== 'object') { | ||
throwError('mount.context must be an object'); | ||
} | ||
var clonedComponent = cloneDeep(component); | ||
component = { | ||
render: function render (h) { | ||
return h( | ||
clonedComponent, | ||
mountingOptions.context || component.FunctionalRenderContext, | ||
(mountingOptions.context && mountingOptions.context.children) || createFunctionalSlots(mountingOptions.slots, h) | ||
) | ||
} | ||
}; | ||
component = createFunctionalComponent(component, mountingOptions); | ||
} else if (mountingOptions.context) { | ||
@@ -1659,2 +1718,4 @@ throwError( | ||
addEventLogger(vue); | ||
var Constructor = vue.extend(component); | ||
@@ -1705,2 +1766,28 @@ | ||
if (typeof Object.assign !== 'function') { | ||
(function () { | ||
Object.assign = function (target) { | ||
'use strict'; | ||
var arguments$1 = arguments; | ||
if (target === undefined || target === null) { | ||
throw new TypeError('Cannot convert undefined or null to object') | ||
} | ||
var output = Object(target); | ||
for (var index = 1; index < arguments.length; index++) { | ||
var source = arguments$1[index]; | ||
if (source !== undefined && source !== null) { | ||
for (var nextKey in source) { | ||
if (source.hasOwnProperty(nextKey)) { | ||
output[nextKey] = source[nextKey]; | ||
} | ||
} | ||
} | ||
} | ||
return output | ||
}; | ||
})(); | ||
} | ||
// | ||
@@ -1707,0 +1794,0 @@ |
{ | ||
"name": "vue-test-utils", | ||
"version": "1.0.0-beta.6", | ||
"version": "1.0.0-beta.7", | ||
"description": "Utilities for testing Vue components.", | ||
@@ -5,0 +5,0 @@ "main": "dist/vue-test-utils.js", |
@@ -111,3 +111,8 @@ import Vue, { VNodeData, Component, ComponentOptions, FunctionalComponentOptions } from 'vue' | ||
interface VueTestUtilsConfigOptions { | ||
stubs?: Stubs | ||
} | ||
export declare function createLocalVue (): typeof Vue | ||
export declare let config: VueTestUtilsConfigOptions | ||
@@ -121,1 +126,4 @@ export declare function mount<V extends Vue, Ctor extends VueClass<V> = VueClass<V>> (component: Ctor, options?: MountOptions<V>): Wrapper<V> | ||
export declare function shallow (component: FunctionalComponentOptions, options?: ShallowOptions<Vue>): Wrapper<Vue> | ||
export declare let TransitionStub: Component | string | true | ||
export declare let TransitionGroupStub: Component | string | true |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
414200
12559