Skip to content

Commit 7b567d3

Browse files
committed
build: update dist files
1 parent 2680859 commit 7b567d3

File tree

4 files changed

+272
-33
lines changed

4 files changed

+272
-33
lines changed

dist/vue-test-utils.amd.js

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,6 +2592,9 @@ function getCoreProperties (component) {
25922592
}
25932593
}
25942594
function createStubFromString (templateString, originalComponent) {
2595+
if (!vueTemplateCompiler.compileToFunctions) {
2596+
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined');
2597+
}
25952598
return Object.assign({}, getCoreProperties(originalComponent),
25962599
vueTemplateCompiler.compileToFunctions(templateString))
25972600
}
@@ -2634,6 +2637,9 @@ function stubComponents (component, stubs) {
26342637
}
26352638
} else {
26362639
if (typeof stubs[stub] === 'string') {
2640+
if (!vueTemplateCompiler.compileToFunctions) {
2641+
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined');
2642+
}
26372643
component.components[stub] = Object.assign({}, vueTemplateCompiler.compileToFunctions(stubs[stub]));
26382644
stubLifeCycleEvents(component.components[stub]);
26392645
} else {
@@ -3067,7 +3073,7 @@ Wrapper.prototype.hasAttribute = function hasAttribute (attribute, value) {
30673073
throwError('wrapper.hasAttribute() must be passed value as a string');
30683074
}
30693075

3070-
return this.element && this.element.getAttribute(attribute) === value
3076+
return !!(this.element && this.element.getAttribute(attribute) === value)
30713077
};
30723078

30733079
/**
@@ -3078,7 +3084,7 @@ Wrapper.prototype.hasClass = function hasClass (className) {
30783084
throwError('wrapper.hasClass() must be passed a string');
30793085
}
30803086

3081-
return this.element.className.split(' ').indexOf(className) !== -1
3087+
return !!(this.element && this.element.classList.contains(className))
30823088
};
30833089

30843090
/**
@@ -3219,7 +3225,10 @@ Wrapper.prototype.is = function is (selector) {
32193225
}
32203226
return vmCtorMatchesName(this.vm, selector.name)
32213227
}
3222-
return this.element.getAttribute && this.element.matches(selector)
3228+
3229+
return !!(this.element &&
3230+
this.element.getAttribute &&
3231+
this.element.matches(selector))
32233232
};
32243233

32253234
/**
@@ -3317,6 +3326,10 @@ Wrapper.prototype.setProps = function setProps (data) {
33173326
* Return text of wrapper element
33183327
*/
33193328
Wrapper.prototype.text = function text () {
3329+
if (!this.element) {
3330+
throwError('cannot call wrapper.text() on a wrapper without an element');
3331+
}
3332+
33203333
return this.element.textContent
33213334
};
33223335

@@ -3330,6 +3343,10 @@ Wrapper.prototype.trigger = function trigger (type, options) {
33303343
throwError('wrapper.trigger() must be passed a string');
33313344
}
33323345

3346+
if (!this.element) {
3347+
throwError('cannot call wrapper.trigger() on a wrapper without an element');
3348+
}
3349+
33333350
var modifiers = {
33343351
enter: 13,
33353352
tab: 9,
@@ -3403,12 +3420,18 @@ function isValidSlot (slot) {
34033420
function addSlotToVm (vm, slotName, slotValue) {
34043421
if (Array.isArray(vm.$slots[slotName])) {
34053422
if (typeof slotValue === 'string') {
3423+
if (!vueTemplateCompiler.compileToFunctions) {
3424+
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined');
3425+
}
34063426
vm.$slots[slotName].push(vm.$createElement(vueTemplateCompiler.compileToFunctions(slotValue)));
34073427
} else {
34083428
vm.$slots[slotName].push(vm.$createElement(slotValue));
34093429
}
34103430
} else {
34113431
if (typeof slotValue === 'string') {
3432+
if (!vueTemplateCompiler.compileToFunctions) {
3433+
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined');
3434+
}
34123435
vm.$slots[slotName] = [vm.$createElement(vueTemplateCompiler.compileToFunctions(slotValue))];
34133436
} else {
34143437
vm.$slots[slotName] = [vm.$createElement(slotValue)]; // eslint-disable-line no-param-reassign
@@ -3444,6 +3467,28 @@ function createInterceptPlugin (interceptedProperties) {
34443467
}
34453468
}
34463469

3470+
function addAttrs (vm, attrs) {
3471+
var consoleWarnSave = console.error;
3472+
console.error = function () {};
3473+
if (attrs) {
3474+
vm.$attrs = attrs;
3475+
} else {
3476+
vm.$attrs = {};
3477+
}
3478+
console.error = consoleWarnSave;
3479+
}
3480+
3481+
function addListeners (vm, listeners) {
3482+
var consoleWarnSave = console.error;
3483+
console.error = function () {};
3484+
if (listeners) {
3485+
vm.$listeners = listeners;
3486+
} else {
3487+
vm.$listeners = {};
3488+
}
3489+
console.error = consoleWarnSave;
3490+
}
3491+
34473492
function addProvide (component, options) {
34483493
var provide = typeof options.provide === 'function'
34493494
? options.provide
@@ -3498,6 +3543,9 @@ function createConstructor (component, options) {
34983543

34993544
var vm = new Constructor(options);
35003545

3546+
addAttrs(vm, options.attrs);
3547+
addListeners(vm, options.listeners);
3548+
35013549
if (options.slots) {
35023550
addSlots(vm, options.slots);
35033551
}
@@ -3580,15 +3628,30 @@ function shallow (component, options) {
35803628

35813629
function createLocalVue () {
35823630
var instance = Vue.extend();
3583-
instance.version = Vue.version;
3584-
instance._installedPlugins = [];
3631+
3632+
// clone global APIs
3633+
Object.keys(Vue).forEach(function (key) {
3634+
if (!instance.hasOwnProperty(key)) {
3635+
var original = Vue[key];
3636+
instance[key] = typeof original === 'object'
3637+
? cloneDeep_1(original)
3638+
: original;
3639+
}
3640+
});
3641+
3642+
// config is not enumerable
35853643
instance.config = cloneDeep_1(Vue.config);
3586-
instance.util = cloneDeep_1(Vue.util);
3587-
instance._use = instance.use;
3644+
3645+
// option merge strategies need to be exposed by reference
3646+
// so that merge strats registered by plguins can work properly
3647+
instance.config.optionMergeStrategies = Vue.config.optionMergeStrategies;
3648+
3649+
// compat for vue-router < 2.7.1 where it does not allow multiple installs
3650+
var use = instance.use;
35883651
instance.use = function (plugin) {
35893652
plugin.installed = false;
35903653
plugin.install.installed = false;
3591-
instance._use(plugin);
3654+
use.call(instance, plugin);
35923655
};
35933656
return instance
35943657
}

dist/vue-test-utils.iife.js

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2593,6 +2593,9 @@ function getCoreProperties (component) {
25932593
}
25942594
}
25952595
function createStubFromString (templateString, originalComponent) {
2596+
if (!vueTemplateCompiler.compileToFunctions) {
2597+
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined');
2598+
}
25962599
return Object.assign({}, getCoreProperties(originalComponent),
25972600
vueTemplateCompiler.compileToFunctions(templateString))
25982601
}
@@ -2635,6 +2638,9 @@ function stubComponents (component, stubs) {
26352638
}
26362639
} else {
26372640
if (typeof stubs[stub] === 'string') {
2641+
if (!vueTemplateCompiler.compileToFunctions) {
2642+
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined');
2643+
}
26382644
component.components[stub] = Object.assign({}, vueTemplateCompiler.compileToFunctions(stubs[stub]));
26392645
stubLifeCycleEvents(component.components[stub]);
26402646
} else {
@@ -3068,7 +3074,7 @@ Wrapper.prototype.hasAttribute = function hasAttribute (attribute, value) {
30683074
throwError('wrapper.hasAttribute() must be passed value as a string');
30693075
}
30703076

3071-
return this.element && this.element.getAttribute(attribute) === value
3077+
return !!(this.element && this.element.getAttribute(attribute) === value)
30723078
};
30733079

30743080
/**
@@ -3079,7 +3085,7 @@ Wrapper.prototype.hasClass = function hasClass (className) {
30793085
throwError('wrapper.hasClass() must be passed a string');
30803086
}
30813087

3082-
return this.element.className.split(' ').indexOf(className) !== -1
3088+
return !!(this.element && this.element.classList.contains(className))
30833089
};
30843090

30853091
/**
@@ -3220,7 +3226,10 @@ Wrapper.prototype.is = function is (selector) {
32203226
}
32213227
return vmCtorMatchesName(this.vm, selector.name)
32223228
}
3223-
return this.element.getAttribute && this.element.matches(selector)
3229+
3230+
return !!(this.element &&
3231+
this.element.getAttribute &&
3232+
this.element.matches(selector))
32243233
};
32253234

32263235
/**
@@ -3318,6 +3327,10 @@ Wrapper.prototype.setProps = function setProps (data) {
33183327
* Return text of wrapper element
33193328
*/
33203329
Wrapper.prototype.text = function text () {
3330+
if (!this.element) {
3331+
throwError('cannot call wrapper.text() on a wrapper without an element');
3332+
}
3333+
33213334
return this.element.textContent
33223335
};
33233336

@@ -3331,6 +3344,10 @@ Wrapper.prototype.trigger = function trigger (type, options) {
33313344
throwError('wrapper.trigger() must be passed a string');
33323345
}
33333346

3347+
if (!this.element) {
3348+
throwError('cannot call wrapper.trigger() on a wrapper without an element');
3349+
}
3350+
33343351
var modifiers = {
33353352
enter: 13,
33363353
tab: 9,
@@ -3404,12 +3421,18 @@ function isValidSlot (slot) {
34043421
function addSlotToVm (vm, slotName, slotValue) {
34053422
if (Array.isArray(vm.$slots[slotName])) {
34063423
if (typeof slotValue === 'string') {
3424+
if (!vueTemplateCompiler.compileToFunctions) {
3425+
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined');
3426+
}
34073427
vm.$slots[slotName].push(vm.$createElement(vueTemplateCompiler.compileToFunctions(slotValue)));
34083428
} else {
34093429
vm.$slots[slotName].push(vm.$createElement(slotValue));
34103430
}
34113431
} else {
34123432
if (typeof slotValue === 'string') {
3433+
if (!vueTemplateCompiler.compileToFunctions) {
3434+
throwError('vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined');
3435+
}
34133436
vm.$slots[slotName] = [vm.$createElement(vueTemplateCompiler.compileToFunctions(slotValue))];
34143437
} else {
34153438
vm.$slots[slotName] = [vm.$createElement(slotValue)]; // eslint-disable-line no-param-reassign
@@ -3456,6 +3479,17 @@ function addAttrs (vm, attrs) {
34563479
console.error = consoleWarnSave;
34573480
}
34583481

3482+
function addListeners (vm, listeners) {
3483+
var consoleWarnSave = console.error;
3484+
console.error = function () {};
3485+
if (listeners) {
3486+
vm.$listeners = listeners;
3487+
} else {
3488+
vm.$listeners = {};
3489+
}
3490+
console.error = consoleWarnSave;
3491+
}
3492+
34593493
function addProvide (component, options) {
34603494
var provide = typeof options.provide === 'function'
34613495
? options.provide
@@ -3511,6 +3545,7 @@ function createConstructor (component, options) {
35113545
var vm = new Constructor(options);
35123546

35133547
addAttrs(vm, options.attrs);
3548+
addListeners(vm, options.listeners);
35143549

35153550
if (options.slots) {
35163551
addSlots(vm, options.slots);
@@ -3594,15 +3629,30 @@ function shallow (component, options) {
35943629

35953630
function createLocalVue () {
35963631
var instance = Vue.extend();
3597-
instance.version = Vue.version;
3598-
instance._installedPlugins = [];
3632+
3633+
// clone global APIs
3634+
Object.keys(Vue).forEach(function (key) {
3635+
if (!instance.hasOwnProperty(key)) {
3636+
var original = Vue[key];
3637+
instance[key] = typeof original === 'object'
3638+
? cloneDeep_1(original)
3639+
: original;
3640+
}
3641+
});
3642+
3643+
// config is not enumerable
35993644
instance.config = cloneDeep_1(Vue.config);
3600-
instance.util = cloneDeep_1(Vue.util);
3601-
instance._use = instance.use;
3645+
3646+
// option merge strategies need to be exposed by reference
3647+
// so that merge strats registered by plguins can work properly
3648+
instance.config.optionMergeStrategies = Vue.config.optionMergeStrategies;
3649+
3650+
// compat for vue-router < 2.7.1 where it does not allow multiple installs
3651+
var use = instance.use;
36023652
instance.use = function (plugin) {
36033653
plugin.installed = false;
36043654
plugin.install.installed = false;
3605-
instance._use(plugin);
3655+
use.call(instance, plugin);
36063656
};
36073657
return instance
36083658
}

0 commit comments

Comments
 (0)