Skip to content

Commit 5056e79

Browse files
committed
build: 1.0.0-beta.2
1 parent 72eb015 commit 5056e79

File tree

4 files changed

+764
-40
lines changed

4 files changed

+764
-40
lines changed

dist/vue-test-utils.amd.js

Lines changed: 191 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,6 +2541,10 @@ function throwError (msg) {
25412541
throw new Error(("[vue-test-utils]: " + msg))
25422542
}
25432543

2544+
function warn (msg) {
2545+
console.error(("[vue-test-utils]: " + msg));
2546+
}
2547+
25442548
//
25452549

25462550
var LIFECYCLE_HOOKS = [
@@ -2917,6 +2921,12 @@ WrapperArray.prototype.throwErrorIfWrappersIsEmpty = function throwErrorIfWrappe
29172921
}
29182922
};
29192923

2924+
WrapperArray.prototype.setComputed = function setComputed (computed) {
2925+
this.throwErrorIfWrappersIsEmpty('setComputed');
2926+
2927+
this.wrappers.forEach(function (wrapper) { return wrapper.setComputed(computed); });
2928+
};
2929+
29202930
WrapperArray.prototype.setData = function setData (data) {
29212931
this.throwErrorIfWrappersIsEmpty('setData');
29222932

@@ -3020,6 +3030,10 @@ ErrorWrapper.prototype.text = function text () {
30203030
throwError(("find did not return " + (this.selector) + ", cannot call text() on empty Wrapper"));
30213031
};
30223032

3033+
ErrorWrapper.prototype.setComputed = function setComputed () {
3034+
throwError(("find did not return " + (this.selector) + ", cannot call setComputed() on empty Wrapper"));
3035+
};
3036+
30233037
ErrorWrapper.prototype.setData = function setData () {
30243038
throwError(("find did not return " + (this.selector) + ", cannot call setData() on empty Wrapper"));
30253039
};
@@ -3047,6 +3061,7 @@ var Wrapper = function Wrapper (vnode, update, options) {
30473061
this.element = vnode.elm;
30483062
this.update = update;
30493063
this.options = options;
3064+
this.version = Number(((Vue.version.split('.')[0]) + "." + (Vue.version.split('.')[1])));
30503065
};
30513066

30523067
Wrapper.prototype.at = function at () {
@@ -3242,9 +3257,7 @@ Wrapper.prototype.findAll = function findAll (selector) {
32423257
* Returns HTML of element as a string
32433258
*/
32443259
Wrapper.prototype.html = function html () {
3245-
var tmp = document.createElement('div');
3246-
tmp.appendChild(this.element);
3247-
return tmp.innerHTML
3260+
return this.element.outerHTML
32483261
};
32493262

32503263
/**
@@ -3274,7 +3287,7 @@ Wrapper.prototype.is = function is (selector) {
32743287
* Checks if node is empty
32753288
*/
32763289
Wrapper.prototype.isEmpty = function isEmpty () {
3277-
return this.vnode.children === undefined
3290+
return this.vnode.children === undefined || this.vnode.children.length === 0
32783291
};
32793292

32803293
/**
@@ -3313,7 +3326,41 @@ Wrapper.prototype.setData = function setData (data) {
33133326
};
33143327

33153328
/**
3316-
* Sets vm data
3329+
* Sets vm computed
3330+
*/
3331+
Wrapper.prototype.setComputed = function setComputed (computed) {
3332+
var this$1 = this;
3333+
3334+
if (!this.isVueComponent) {
3335+
throwError('wrapper.setComputed() can only be called on a Vue instance');
3336+
}
3337+
3338+
Object.keys(computed).forEach(function (key) {
3339+
if (this$1.version > 2.1) {
3340+
// $FlowIgnore : Problem with possibly null this.vm
3341+
if (!this$1.vm._computedWatchers[key]) {
3342+
throwError(("wrapper.setComputed() was passed a value that does not exist as a computed property on the Vue instance. Property " + key + " does not exist on the Vue instance"));
3343+
}
3344+
// $FlowIgnore : Problem with possibly null this.vm
3345+
this$1.vm._computedWatchers[key].value = computed[key];
3346+
} else {
3347+
// $FlowIgnore : Problem with possibly null this.vm
3348+
if (!this$1.vm._watchers.some(function (w) { return w.getter.name === key; })) {
3349+
throwError(("wrapper.setComputed() was passed a value that does not exist as a computed property on the Vue instance. Property " + key + " does not exist on the Vue instance"));
3350+
}
3351+
// $FlowIgnore : Problem with possibly null this.vm
3352+
this$1.vm._watchers.forEach(function (watcher) {
3353+
if (watcher.getter.name === key) {
3354+
watcher.value = computed[key];
3355+
}
3356+
});
3357+
}
3358+
});
3359+
this.update();
3360+
};
3361+
3362+
/**
3363+
* Sets vm methods
33173364
*/
33183365
Wrapper.prototype.setMethods = function setMethods (methods) {
33193366
var this$1 = this;
@@ -3439,6 +3486,7 @@ function logEvents (vm, emitted, emittedByOrder) {
34393486

34403487
function update () {
34413488
this._update(this._render());
3489+
this.$children.forEach(function (child) { return update.call(child); });
34423490
}
34433491

34443492
var VueWrapper = (function (Wrapper$$1) {
@@ -3450,7 +3498,11 @@ var VueWrapper = (function (Wrapper$$1) {
34503498
get: function () { return vm._vnode; },
34513499
set: function () {}
34523500
}));
3453-
3501+
// $FlowIgnore
3502+
Object.defineProperty(this, 'element', ({
3503+
get: function () { return vm.$el; },
3504+
set: function () {}
3505+
}));
34543506
this.vm = vm;
34553507
this.isVueComponent = true;
34563508
this._emitted = Object.create(null);
@@ -3519,23 +3571,25 @@ function addMocks (mockedProperties, Vue$$1) {
35193571
}
35203572

35213573
function addAttrs (vm, attrs) {
3574+
var originalVueConfig = Vue.config;
35223575
Vue.config.silent = true;
35233576
if (attrs) {
35243577
vm.$attrs = attrs;
35253578
} else {
35263579
vm.$attrs = {};
35273580
}
3528-
Vue.config.silent = false;
3581+
Vue.config.silent = originalVueConfig.silent;
35293582
}
35303583

35313584
function addListeners (vm, listeners) {
3585+
var originalVueConfig = Vue.config;
35323586
Vue.config.silent = true;
35333587
if (listeners) {
35343588
vm.$listeners = listeners;
35353589
} else {
35363590
vm.$listeners = {};
35373591
}
3538-
Vue.config.silent = false;
3592+
Vue.config.silent = originalVueConfig.silent;
35393593
}
35403594

35413595
function addProvide (component, options) {
@@ -3648,7 +3702,7 @@ function mount (component, options) {
36483702
throwError(
36493703
'window is undefined, vue-test-utils needs to be run in a browser environment.\n' +
36503704
'You can run the tests in node using jsdom + jsdom-global.\n' +
3651-
'See https://vue-test-utils.vuejs.org/en/guides/general-tips.html for more details.'
3705+
'See https://vue-test-utils.vuejs.org/en/guides/common-tips.html for more details.'
36523706
);
36533707
}
36543708

@@ -3721,10 +3775,137 @@ function createLocalVue () {
37213775
return instance
37223776
}
37233777

3778+
//
3779+
3780+
function getRealChild (vnode) {
3781+
var compOptions = vnode && vnode.componentOptions;
3782+
if (compOptions && compOptions.Ctor.options.abstract) {
3783+
return getRealChild(getFirstComponentChild(compOptions.children))
3784+
} else {
3785+
return vnode
3786+
}
3787+
}
3788+
3789+
function getFirstComponentChild (children) {
3790+
if (Array.isArray(children)) {
3791+
for (var i = 0; i < children.length; i++) {
3792+
var c = children[i];
3793+
if (c && (c.componentOptions || isAsyncPlaceholder(c))) {
3794+
return c
3795+
}
3796+
}
3797+
}
3798+
}
3799+
3800+
function isAsyncPlaceholder (node) {
3801+
return node.isComment && node.asyncFactory
3802+
}
3803+
var camelizeRE = /-(\w)/g;
3804+
var camelize = function (str) {
3805+
return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })
3806+
};
3807+
3808+
function extractTransitionData (comp) {
3809+
var data = {};
3810+
var options = comp.$options;
3811+
// props
3812+
for (var key in options.propsData) {
3813+
data[key] = comp[key];
3814+
}
3815+
// events.
3816+
// extract listeners and pass them directly to the transition methods
3817+
var listeners = options._parentListeners;
3818+
for (var key$1 in listeners) {
3819+
data[camelize(key$1)] = listeners[key$1];
3820+
}
3821+
return data
3822+
}
3823+
3824+
function hasParentTransition (vnode) {
3825+
while ((vnode = vnode.parent)) {
3826+
if (vnode.data.transition) {
3827+
return true
3828+
}
3829+
}
3830+
}
3831+
3832+
var TransitionStub = {
3833+
render: function render (h) {
3834+
var children = this.$options._renderChildren;
3835+
if (!children) {
3836+
return
3837+
}
3838+
3839+
// filter out text nodes (possible whitespaces)
3840+
children = children.filter(function (c) { return c.tag || isAsyncPlaceholder(c); });
3841+
/* istanbul ignore if */
3842+
if (!children.length) {
3843+
return
3844+
}
3845+
3846+
// warn multiple elements
3847+
if (children.length > 1) {
3848+
warn(
3849+
'<transition> can only be used on a single element. Use ' +
3850+
'<transition-group> for lists.'
3851+
);
3852+
}
3853+
3854+
var mode = this.mode;
3855+
3856+
// warn invalid mode
3857+
if (mode && mode !== 'in-out' && mode !== 'out-in'
3858+
) {
3859+
warn(
3860+
'invalid <transition> mode: ' + mode
3861+
);
3862+
}
3863+
3864+
var rawChild = children[0];
3865+
3866+
// if this is a component root node and the component's
3867+
// parent container node also has transition, skip.
3868+
if (hasParentTransition(this.$vnode)) {
3869+
return rawChild
3870+
}
3871+
3872+
// apply transition data to child
3873+
// use getRealChild() to ignore abstract components e.g. keep-alive
3874+
var child = getRealChild(rawChild);
3875+
3876+
if (!child) {
3877+
return rawChild
3878+
}
3879+
3880+
(child.data || (child.data = {})).transition = extractTransitionData(this);
3881+
3882+
// mark v-show
3883+
// so that the transition module can hand over the control to the directive
3884+
if (child.data.directives && child.data.directives.some(function (d) { return d.name === 'show'; })) {
3885+
child.data.show = true;
3886+
}
3887+
3888+
return rawChild
3889+
}
3890+
};
3891+
3892+
//
3893+
3894+
var TransitionGroupStub = {
3895+
render: function render (h) {
3896+
var tag = this.tag || this.$vnode.data.tag || 'span';
3897+
var children = this.$slots.default || [];
3898+
3899+
return h(tag, null, children)
3900+
}
3901+
};
3902+
37243903
var index = {
37253904
createLocalVue: createLocalVue,
37263905
mount: mount,
3727-
shallow: shallow
3906+
shallow: shallow,
3907+
TransitionStub: TransitionStub,
3908+
TransitionGroupStub: TransitionGroupStub
37283909
};
37293910

37303911
return index;

0 commit comments

Comments
 (0)