diff --git a/packages/create-instance/add-hook.js b/packages/create-instance/add-hook.js
deleted file mode 100644
index f875ff173..000000000
--- a/packages/create-instance/add-hook.js
+++ /dev/null
@@ -1,10 +0,0 @@
-// This is used instead of Vue.mixin. The reason is that
-// Vue.mixin is slower, and remove modified options
-// https://github.com/vuejs/vue/issues/8710
-
-export function addHook (options, hook, fn) {
- if (options[hook] && !Array.isArray(options[hook])) {
- options[hook] = [options[hook]]
- }
- (options[hook] || (options[hook] = [])).push(fn)
-}
diff --git a/packages/create-instance/add-stubs.js b/packages/create-instance/add-stubs.js
index e4049c1df..dd6c8a380 100644
--- a/packages/create-instance/add-stubs.js
+++ b/packages/create-instance/add-stubs.js
@@ -1,12 +1,11 @@
-import { addHook } from './add-hook'
+import { BEFORE_RENDER_LIFECYCLE_HOOK } from 'shared/consts'
export function addStubs (_Vue, stubComponents) {
function addStubComponentsMixin () {
Object.assign(this.$options.components, stubComponents)
}
- addHook(_Vue.options, 'beforeMount', addStubComponentsMixin)
- // beforeCreate is for components created in node, which
- // never mount
- addHook(_Vue.options, 'beforeCreate', addStubComponentsMixin)
+ _Vue.mixin({
+ [BEFORE_RENDER_LIFECYCLE_HOOK]: addStubComponentsMixin
+ })
}
diff --git a/packages/create-instance/log-events.js b/packages/create-instance/log-events.js
index dfc964357..03a824809 100644
--- a/packages/create-instance/log-events.js
+++ b/packages/create-instance/log-events.js
@@ -1,5 +1,4 @@
// @flow
-import { addHook } from './add-hook'
export function logEvents (
vm: Component,
@@ -15,10 +14,11 @@ export function logEvents (
}
export function addEventLogger (_Vue: Component): void {
- addHook(_Vue.options, 'beforeCreate', function () {
- this.__emitted = Object.create(null)
- this.__emittedByOrder = []
- logEvents(this, this.__emitted, this.__emittedByOrder)
- }
- )
+ _Vue.mixin({
+ beforeCreate: function () {
+ this.__emitted = Object.create(null)
+ this.__emittedByOrder = []
+ logEvents(this, this.__emitted, this.__emittedByOrder)
+ }
+ })
}
diff --git a/packages/create-instance/patch-render.js b/packages/create-instance/patch-render.js
index b4911ebbc..4ab5dca47 100644
--- a/packages/create-instance/patch-render.js
+++ b/packages/create-instance/patch-render.js
@@ -1,8 +1,8 @@
import { createStubFromComponent } from './create-component-stubs'
import { resolveComponent, semVerGreaterThan } from 'shared/util'
import { isReservedTag } from 'shared/validators'
-import { addHook } from './add-hook'
import Vue from 'vue'
+import { BEFORE_RENDER_LIFECYCLE_HOOK } from 'shared/consts'
const isWhitelisted = (el, whitelist) => resolveComponent(el, whitelist)
const isAlreadyStubbed = (el, stubs) => stubs.has(el)
@@ -11,9 +11,6 @@ const isDynamicComponent = cmp => typeof cmp === 'function' && !cmp.cid
const CREATE_ELEMENT_ALIAS = semVerGreaterThan(Vue.version, '2.1.5')
? '_c'
: '_h'
-const LIFECYCLE_HOOK = semVerGreaterThan(Vue.version, '2.1.8')
- ? 'beforeCreate'
- : 'beforeMount'
function shouldExtend (component, _Vue) {
return (
@@ -126,5 +123,7 @@ export function patchRender (_Vue, stubs, stubAllComponents) {
vm.$createElement = createElement
}
- addHook(_Vue.options, LIFECYCLE_HOOK, patchRenderMixin)
+ _Vue.mixin({
+ [BEFORE_RENDER_LIFECYCLE_HOOK]: patchRenderMixin
+ })
}
diff --git a/packages/test-utils/src/consts.js b/packages/shared/consts.js
similarity index 72%
rename from packages/test-utils/src/consts.js
rename to packages/shared/consts.js
index fa4c1e01a..30b437426 100644
--- a/packages/test-utils/src/consts.js
+++ b/packages/shared/consts.js
@@ -1,4 +1,5 @@
import Vue from 'vue'
+import { semVerGreaterThan } from './util'
export const NAME_SELECTOR = 'NAME_SELECTOR'
export const COMPONENT_SELECTOR = 'COMPONENT_SELECTOR'
@@ -10,3 +11,8 @@ export const VUE_VERSION = Number(
)
export const FUNCTIONAL_OPTIONS =
VUE_VERSION >= 2.5 ? 'fnOptions' : 'functionalOptions'
+
+export const BEFORE_RENDER_LIFECYCLE_HOOK =
+ semVerGreaterThan(Vue.version, '2.1.8')
+ ? 'beforeCreate'
+ : 'beforeMount'
diff --git a/packages/test-utils/src/find.js b/packages/test-utils/src/find.js
index dd5c22a8b..47b3c920d 100644
--- a/packages/test-utils/src/find.js
+++ b/packages/test-utils/src/find.js
@@ -5,7 +5,7 @@ import {
DOM_SELECTOR,
REF_SELECTOR,
COMPONENT_SELECTOR
-} from './consts'
+} from 'shared/consts'
import { throwError, vueVersion } from 'shared/util'
import { matches } from './matches'
diff --git a/packages/test-utils/src/get-selector.js b/packages/test-utils/src/get-selector.js
index ce14e2e11..548d1f253 100644
--- a/packages/test-utils/src/get-selector.js
+++ b/packages/test-utils/src/get-selector.js
@@ -13,7 +13,7 @@ import {
NAME_SELECTOR,
DOM_SELECTOR,
INVALID_SELECTOR
-} from './consts'
+} from 'shared/consts'
function getSelectorType (
selector: Selector
diff --git a/packages/test-utils/src/matches.js b/packages/test-utils/src/matches.js
index c86c531bc..cefe400d6 100644
--- a/packages/test-utils/src/matches.js
+++ b/packages/test-utils/src/matches.js
@@ -2,7 +2,7 @@ import {
DOM_SELECTOR,
COMPONENT_SELECTOR,
FUNCTIONAL_OPTIONS
-} from './consts'
+} from 'shared/consts'
export function vmMatchesName (vm, name) {
return !!name && (
diff --git a/packages/test-utils/src/set-watchers-to-sync.js b/packages/test-utils/src/set-watchers-to-sync.js
index e59d62133..0b2de07bd 100644
--- a/packages/test-utils/src/set-watchers-to-sync.js
+++ b/packages/test-utils/src/set-watchers-to-sync.js
@@ -1,6 +1,6 @@
// @flow
-import { VUE_VERSION } from './consts'
+import { VUE_VERSION } from 'shared/consts'
function setDepsSync (dep): void {
dep.subs.forEach(setWatcherSync)
diff --git a/packages/test-utils/src/wrapper.js b/packages/test-utils/src/wrapper.js
index dae492e5b..4d13e0c25 100644
--- a/packages/test-utils/src/wrapper.js
+++ b/packages/test-utils/src/wrapper.js
@@ -5,7 +5,7 @@ import getSelector from './get-selector'
import {
REF_SELECTOR,
FUNCTIONAL_OPTIONS
-} from './consts'
+} from 'shared/consts'
import config from './config'
import WrapperArray from './wrapper-array'
import ErrorWrapper from './error-wrapper'
diff --git a/test/specs/mounting-options/localVue.spec.js b/test/specs/mounting-options/localVue.spec.js
index 38e9392cc..6706bdf72 100644
--- a/test/specs/mounting-options/localVue.spec.js
+++ b/test/specs/mounting-options/localVue.spec.js
@@ -4,7 +4,7 @@ import {
isRunningPhantomJS,
vueVersion
} from '~resources/utils'
-import { createLocalVue } from '~vue/test-utils'
+import { createLocalVue, shallowMount, mount } from '~vue/test-utils'
import { itSkipIf, itRunIf, itDoNotRunIf } from 'conditional-specs'
import Vuex from 'vuex'
@@ -196,4 +196,21 @@ describeWithMountingMethods('options.localVue', mountingMethod => {
}
expect(wrapper.findAll(ChildComponent).length).to.equal(1)
})
+
+ itRunIf(
+ mountingMethod.name === 'mount',
+ 'does not affect future tests', () => {
+ const ChildComponent = {
+ template: ''
+ }
+ const TestComponent = {
+ template: '',
+ components: { ChildComponent }
+ }
+ const localVue = createLocalVue()
+ localVue.use(Vuex)
+ shallowMount(TestComponent, { localVue })
+ const wrapper = mount(TestComponent, { localVue })
+ expect(wrapper.html()).to.contain('span')
+ })
})