Skip to content

Commit 5dc0010

Browse files
committed
build: update dist
1 parent 72b11ca commit 5dc0010

File tree

1 file changed

+56
-36
lines changed

1 file changed

+56
-36
lines changed

dist/vue-test-utils.js

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function stubLifeCycleEvents (component) {
3636
function isValidStub (stub) {
3737
return !!stub &&
3838
(typeof stub === 'string' ||
39+
(stub === true) ||
3940
(typeof stub === 'object' &&
4041
typeof stub.render === 'function'))
4142
}
@@ -67,35 +68,47 @@ function createBlankStub (originalComponent) {
6768
}
6869

6970
function stubComponents (component, stubs) {
70-
Object.keys(stubs).forEach(function (stub) {
71-
if (!isValidStub(stubs[stub])) {
72-
throwError('options.stub values must be passed a string or component');
73-
}
74-
75-
if (!component.components) {
76-
component.components = {};
77-
}
71+
if (!component.components) {
72+
component.components = {};
73+
}
7874

79-
if (component.components[stub]) {
80-
// Remove cached constructor
81-
delete component.components[stub]._Ctor;
82-
if (typeof stubs[stub] === 'string') {
83-
component.components[stub] = createStubFromString(stubs[stub], component.components[stub]);
84-
stubLifeCycleEvents(component.components[stub]);
85-
} else {
86-
component.components[stub] = Object.assign({}, stubs[stub],
87-
{name: component.components[stub].name});
75+
if (Array.isArray(stubs)) {
76+
stubs.forEach(function (stub) {
77+
if (typeof stub !== 'string') {
78+
throwError('each item in options.stub must be a string');
8879
}
89-
} else {
90-
if (typeof stubs[stub] === 'string') {
91-
component.components[stub] = Object.assign({}, vueTemplateCompiler.compileToFunctions(stubs[stub]));
92-
stubLifeCycleEvents(component.components[stub]);
80+
component.components[stub] = createBlankStub({});
81+
});
82+
} else {
83+
Object.keys(stubs).forEach(function (stub) {
84+
if (!isValidStub(stubs[stub])) {
85+
throwError('options.stub values must be passed a string or component');
86+
}
87+
if (stubs[stub] === true) {
88+
component.components[stub] = createBlankStub({});
89+
return
90+
}
91+
if (component.components[stub]) {
92+
// Remove cached constructor
93+
delete component.components[stub]._Ctor;
94+
if (typeof stubs[stub] === 'string') {
95+
component.components[stub] = createStubFromString(stubs[stub], component.components[stub]);
96+
stubLifeCycleEvents(component.components[stub]);
97+
} else {
98+
component.components[stub] = Object.assign({}, stubs[stub],
99+
{name: component.components[stub].name});
100+
}
93101
} else {
94-
component.components[stub] = Object.assign({}, stubs[stub]);
102+
if (typeof stubs[stub] === 'string') {
103+
component.components[stub] = Object.assign({}, vueTemplateCompiler.compileToFunctions(stubs[stub]));
104+
stubLifeCycleEvents(component.components[stub]);
105+
} else {
106+
component.components[stub] = Object.assign({}, stubs[stub]);
107+
}
95108
}
96-
}
97-
Vue.config.ignoredElements.push(stub);
98-
});
109+
Vue.config.ignoredElements.push(stub);
110+
});
111+
}
99112
}
100113

101114
function stubAllComponents (component) {
@@ -645,7 +658,9 @@ Wrapper.prototype.is = function is (selector) {
645658
if (!this.isVueComponent) {
646659
return false
647660
}
648-
// TODO: Throw error if component does not have name
661+
if (typeof selector.name !== 'string') {
662+
throwError('a Component used as a selector must have a name property');
663+
}
649664
return vmCtorMatchesName(this.vm, selector.name)
650665
}
651666
return this.element.getAttribute && this.element.matches(selector)
@@ -706,7 +721,9 @@ Wrapper.prototype.setProps = function setProps (data) {
706721
Object.keys(data).forEach(function (key) {
707722
// $FlowIgnore : Problem with possibly null this.vm
708723
this$1.vm._props[key] = data[key];
709-
// $FlowIgnore : Problem with possibly null this.vm
724+
});
725+
Object.keys(data).forEach(function (key) {
726+
// $FlowIgnore : Problem with possibly null this.vm
710727
this$1.vm._watchers.forEach(function (watcher) {
711728
if (watcher.expression === key) { watcher.run(); }
712729
});
@@ -837,11 +854,11 @@ function addSlots (vm, slots) {
837854

838855
//
839856

840-
function addGlobals (globals) {
857+
function createInterceptPlugin (interceptedProperties) {
841858
return {
842859
install: function (Vue$$1) {
843-
Object.keys(globals).forEach(function (key) {
844-
Vue$$1.prototype[key] = globals[key];
860+
Object.keys(interceptedProperties).forEach(function (key) {
861+
Vue$$1.prototype[key] = interceptedProperties[key];
845862
});
846863
}
847864
}
@@ -886,15 +903,17 @@ function createConstructor (component, options) {
886903
addProvide(component, options);
887904
}
888905

889-
if (options.stub) {
890-
stubComponents(component, options.stub);
906+
if (options.stubs) {
907+
stubComponents(component, options.stubs);
891908
}
892909

893910
var Constructor = vue.extend(component);
894911

895912
if (options.intercept) {
896-
var globals = addGlobals(options.intercept);
897-
Constructor.use(globals);
913+
// creates a plugin that adds properties, and then install on local Constructor
914+
// this does not affect the base Vue class
915+
var interceptPlugin = createInterceptPlugin(options.intercept);
916+
Constructor.use(interceptPlugin);
898917
}
899918

900919
var vm = new Constructor(options);
@@ -945,10 +964,11 @@ function mount (component, options) {
945964
throwError('window is undefined, vue-test-utils needs to be run in a browser environment.\n You can run the tests in node using JSDOM');
946965
}
947966

967+
var componentToMount = options.clone === false ? component : lodash.cloneDeep(component);
948968
// Remove cached constructor
949-
delete component._Ctor;
969+
delete componentToMount._Ctor;
950970

951-
var vm = createConstructor(component, options);
971+
var vm = createConstructor(componentToMount, options);
952972

953973
if (options.attachToDocument) {
954974
vm.$mount(createElement());

0 commit comments

Comments
 (0)