Skip to content

Commit de9553f

Browse files
committed
build: 1.0.0-beta.4
1 parent 92993df commit de9553f

6 files changed

+384
-220
lines changed

dist/vue-test-utils.amd.js

Lines changed: 94 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,6 +2965,12 @@ WrapperArray.prototype.update = function update () {
29652965
this.wrappers.forEach(function (wrapper) { return wrapper.update(); });
29662966
};
29672967

2968+
WrapperArray.prototype.destroy = function destroy () {
2969+
this.throwErrorIfWrappersIsEmpty('destroy');
2970+
2971+
this.wrappers.forEach(function (wrapper) { return wrapper.destroy(); });
2972+
};
2973+
29682974
//
29692975
var ErrorWrapper = function ErrorWrapper (selector) {
29702976
this.selector = selector;
@@ -3062,6 +3068,10 @@ ErrorWrapper.prototype.update = function update () {
30623068
throwError(("find did not return " + (this.selector) + ", cannot call update() on empty Wrapper"));
30633069
};
30643070

3071+
ErrorWrapper.prototype.destroy = function destroy () {
3072+
throwError(("find did not return " + (this.selector) + ", cannot call destroy() on empty Wrapper"));
3073+
};
3074+
30653075
//
30663076

30673077
var Wrapper = function Wrapper (vnode, update, options) {
@@ -3142,6 +3152,8 @@ Wrapper.prototype.hasAttribute = function hasAttribute (attribute, value) {
31423152
* Asserts wrapper has a class name
31433153
*/
31443154
Wrapper.prototype.hasClass = function hasClass (className) {
3155+
var this$1 = this;
3156+
31453157
var targetClass = className;
31463158

31473159
if (typeof targetClass !== 'string') {
@@ -3153,7 +3165,11 @@ Wrapper.prototype.hasClass = function hasClass (className) {
31533165
targetClass = this.vm.$style[targetClass];
31543166
}
31553167

3156-
return !!(this.element && this.element.classList.contains(targetClass))
3168+
var containsAllClasses = targetClass
3169+
.split(' ')
3170+
.every(function (target) { return this$1.element.classList.contains(target); });
3171+
3172+
return !!(this.element && containsAllClasses)
31573173
};
31583174

31593175
/**
@@ -3434,6 +3450,21 @@ Wrapper.prototype.text = function text () {
34343450
return this.element.textContent
34353451
};
34363452

3453+
/**
3454+
* Calls destroy on vm
3455+
*/
3456+
Wrapper.prototype.destroy = function destroy () {
3457+
if (!this.isVueComponent) {
3458+
throwError('wrapper.destroy() can only be called on a Vue instance');
3459+
}
3460+
3461+
if (this.element.parentNode) {
3462+
this.element.parentNode.removeChild(this.element);
3463+
}
3464+
// $FlowIgnore
3465+
this.vm.$destroy();
3466+
};
3467+
34373468
/**
34383469
* Dispatches a DOM event on wrapper
34393470
*/
@@ -3578,10 +3609,10 @@ function addSlots (vm, slots) {
35783609
}
35793610

35803611
//
3581-
35823612
function addMocks (mockedProperties, Vue$$1) {
35833613
Object.keys(mockedProperties).forEach(function (key) {
35843614
Vue$$1.prototype[key] = mockedProperties[key];
3615+
Vue.util.defineReactive(Vue$$1, key, mockedProperties[key]);
35853616
});
35863617
}
35873618

@@ -3629,23 +3660,77 @@ function compileTemplate (component) {
36293660

36303661
//
36313662

3632-
function createConstructor (component, options) {
3633-
var vue = options.localVue || Vue;
3663+
function createLocalVue () {
3664+
var instance = Vue.extend();
3665+
3666+
// clone global APIs
3667+
Object.keys(Vue).forEach(function (key) {
3668+
if (!instance.hasOwnProperty(key)) {
3669+
var original = Vue[key];
3670+
instance[key] = typeof original === 'object'
3671+
? cloneDeep_1(original)
3672+
: original;
3673+
}
3674+
});
36343675

3635-
if (options.context) {
3636-
if (!component.functional) {
3637-
throwError('mount.context can only be used when mounting a functional component');
3676+
// config is not enumerable
3677+
instance.config = cloneDeep_1(Vue.config);
3678+
3679+
// option merge strategies need to be exposed by reference
3680+
// so that merge strats registered by plguins can work properly
3681+
instance.config.optionMergeStrategies = Vue.config.optionMergeStrategies;
3682+
3683+
// make sure all extends are based on this instance.
3684+
// this is important so that global components registered by plugins,
3685+
// e.g. router-link are created using the correct base constructor
3686+
instance.options._base = instance;
3687+
3688+
// compat for vue-router < 2.7.1 where it does not allow multiple installs
3689+
var use = instance.use;
3690+
instance.use = function (plugin) {
3691+
var rest = [], len = arguments.length - 1;
3692+
while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ];
3693+
3694+
if (plugin.installed === true) {
3695+
plugin.installed = false;
3696+
}
3697+
if (plugin.install && plugin.install.installed === true) {
3698+
plugin.install.installed = false;
36383699
}
3700+
use.call.apply(use, [ instance, plugin ].concat( rest ));
3701+
};
3702+
return instance
3703+
}
36393704

3640-
if (typeof options.context !== 'object') {
3705+
//
3706+
3707+
function createConstructor (
3708+
component,
3709+
options
3710+
) {
3711+
var vue = options.localVue || createLocalVue();
3712+
3713+
if (options.mocks) {
3714+
addMocks(options.mocks, vue);
3715+
}
3716+
3717+
if (component.functional) {
3718+
if (options.context && typeof options.context !== 'object') {
36413719
throwError('mount.context must be an object');
36423720
}
36433721
var clonedComponent = cloneDeep_1(component);
36443722
component = {
36453723
render: function render (h) {
3646-
return h(clonedComponent, options.context)
3724+
return h(
3725+
clonedComponent,
3726+
options.context || component.FunctionalRenderContext
3727+
)
36473728
}
36483729
};
3730+
} else if (options.context) {
3731+
throwError(
3732+
'mount.context can only be used when mounting a functional component'
3733+
);
36493734
}
36503735

36513736
if (options.provide) {
@@ -3662,10 +3747,6 @@ function createConstructor (component, options) {
36623747

36633748
var Constructor = vue.extend(component);
36643749

3665-
if (options.mocks) {
3666-
addMocks(options.mocks, Constructor);
3667-
}
3668-
36693750
var vm = new Constructor(options);
36703751

36713752
addAttrs(vm, options.attrs);
@@ -3747,46 +3828,6 @@ function shallow (component, options) {
37473828

37483829
//
37493830

3750-
function createLocalVue () {
3751-
var instance = Vue.extend();
3752-
3753-
// clone global APIs
3754-
Object.keys(Vue).forEach(function (key) {
3755-
if (!instance.hasOwnProperty(key)) {
3756-
var original = Vue[key];
3757-
instance[key] = typeof original === 'object'
3758-
? cloneDeep_1(original)
3759-
: original;
3760-
}
3761-
});
3762-
3763-
// config is not enumerable
3764-
instance.config = cloneDeep_1(Vue.config);
3765-
3766-
// option merge strategies need to be exposed by reference
3767-
// so that merge strats registered by plguins can work properly
3768-
instance.config.optionMergeStrategies = Vue.config.optionMergeStrategies;
3769-
3770-
// make sure all extends are based on this instance.
3771-
// this is important so that global components registered by plugins,
3772-
// e.g. router-link are created using the correct base constructor
3773-
instance.options._base = instance;
3774-
3775-
// compat for vue-router < 2.7.1 where it does not allow multiple installs
3776-
var use = instance.use;
3777-
instance.use = function (plugin) {
3778-
var rest = [], len = arguments.length - 1;
3779-
while ( len-- > 0 ) rest[ len ] = arguments[ len + 1 ];
3780-
3781-
plugin.installed = false;
3782-
plugin.install.installed = false;
3783-
use.call.apply(use, [ instance, plugin ].concat( rest ));
3784-
};
3785-
return instance
3786-
}
3787-
3788-
//
3789-
37903831
function getRealChild (vnode) {
37913832
var compOptions = vnode && vnode.componentOptions;
37923833
if (compOptions && compOptions.Ctor.options.abstract) {

0 commit comments

Comments
 (0)