Skip to content

Commit a2137fa

Browse files
committed
refactor: rename scopedVue and instance to createLocalVue and localVue
1 parent d495102 commit a2137fa

13 files changed

+64
-65
lines changed

docs/en/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
* [Introduction](README.md)
44
* [API](api/README.md)
5+
* [createLocalVue](api/createLocalVue.md)
56
* [mount](api/mount.md)
67
* [shallow](api/shallow.md)
7-
* [scopedVue](api/scopedVue.md)
88
* [Wrapper](api/wrapper/README.md)
99
* [contains](api/wrapper/contains.md)
1010
* [find](api/wrapper/find.md)

docs/en/api/createLocalVue.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# createLocalVue()
2+
3+
- **Returns:**
4+
- `{Component}`
5+
6+
- **Usage:**
7+
8+
createLocalVue returns a Vue class for you to add components, mixins and install plugins without polluting the global Vue class.
9+
10+
Use it with `options.localVue`
11+
12+
```js
13+
import { createLocalVue, shallow } from 'vue-test-utils'
14+
import { expect } from 'chai'
15+
import Foo from './Foo.vue'
16+
17+
const localVue = createLocalVue()
18+
const wrapper = shallow(Foo, {
19+
localVue,
20+
intercept: { foo: true }
21+
})
22+
expect(wrapper.vm.foo).to.equal(true)
23+
24+
const freshWrapper = shallow(Foo)
25+
expect(freshWrapper.vm.foo).to.equal(false)
26+
```

docs/en/api/mount.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
`options.context` (`Object`): Passes context to functional component. Can only be used with functional components
2727

28+
`options.localVue` ('Object): vue class to use in `mount`. See [createLocalVue](/api/createLocalVue.md)
29+
2830
`options.slots` (`Object`): Render component with slots.
2931

3032
`options.slots.default` (`Array[Component]|Component|String`): Default slot object to render, can be a Vue component or array of Vue components
@@ -33,9 +35,7 @@
3335

3436
`options.globals` (`Object`): Add globals to Vue instance.
3537

36-
`options.instance` ('Object): instance for vue-test-utils to use. See [scopedVue](/api/scopedVue.md)
37-
38-
`options.stub` ('Object): Stubs components matchng the name passed with a string
38+
`options.stub` ('Object): Stubs components matching the name passed with a string
3939

4040
- **Usage:**
4141

docs/en/api/scopedVue.md

-27
This file was deleted.

docs/en/api/shallow.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
`options.context` (`Object`): Passes context to functional component. Can only be used with functional components
2727

28+
`options.localVue` ('Object): vue class to use in `mount`. See [createLocalVue](/api/createLocalVue.md)
29+
2830
`options.slots` (`Object`): Render component with slots.
2931

3032
`options.slots.default` (`Array[Component]|Component|String`): Default slot object to render, can be a Vue component or array of Vue components
@@ -33,9 +35,7 @@
3335

3436
`options.globals` (`Object`): Add globals to Vue instance.
3537

36-
`options.instance` ('Object): instance for vue-test-utils to use. See [scopedVue](/api/scopedVue.md)
37-
38-
`options.stub` ('Object): Stubs components matchng the name passed with a string
38+
`options.stub` ('Object): Stubs components matching the name passed with a string
3939

4040
- **Usage:**
4141

flow/options.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ declare type Options = { // eslint-disable-line no-undef
22
attachToDocument?: boolean,
33
intercept?: Object,
44
slots?: Object,
5-
instance?: Component,
5+
localVue?: Component,
66
stub?: Object,
77
context?: Object
88
}

src/scoped-vue.js src/create-local-vue.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import Vue from 'vue'
44
import { cloneDeep } from 'lodash'
55

6-
function scopedVue (): Component {
6+
function createLocalVue (): Component {
77
const instance = Vue.extend()
88
instance.version = Vue.version
99
instance.config = cloneDeep(Vue.config)
1010
instance.util = cloneDeep(Vue.util)
1111
return instance
1212
}
1313

14-
export default scopedVue
14+
export default createLocalVue

src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import shallow from './shallow'
22
import mount from './mount'
3-
import scopedVue from './scoped-vue'
3+
import createLocalVue from './create-local-vue'
44

55
export default {
6+
createLocalVue,
67
mount,
7-
shallow,
8-
scopedVue
8+
shallow
99
}

src/lib/create-instance.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { throwError } from './util'
99
import { cloneDeep } from 'lodash'
1010

1111
export default function createConstructor (component: Component, options: Options): Component {
12-
const instance = options.instance || Vue
12+
const vue = options.localVue || Vue
1313

1414
if (options.context) {
1515
if (!component.functional) {
@@ -35,7 +35,7 @@ export default function createConstructor (component: Component, options: Option
3535
stubComponents(component, options.stub)
3636
}
3737

38-
const Constructor = instance.extend(component)
38+
const Constructor = vue.extend(component)
3939

4040
if (options.intercept) {
4141
const globals = addGlobals(options.intercept)

src/shallow.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import mount from './mount'
1010
import type VueWrapper from './wrappers/vue-wrapper'
1111

1212
export default function shallow (component: Component, options: Options = {}): VueWrapper {
13-
const instance = options.instance || Vue
13+
const vue = options.localVue || Vue
1414
const clonedComponent = cloneDeep(component)
1515

1616
if (clonedComponent.components) {
1717
stubAllComponents(clonedComponent)
1818
}
1919

20-
stubGlobalComponents(clonedComponent, instance)
20+
stubGlobalComponents(clonedComponent, vue)
2121

2222
return mount(clonedComponent, options)
2323
}

test/integration/specs/scoped-vue.spec.js test/integration/specs/create-local-vue.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import scopedVue from '~src/scoped-vue'
1+
import createLocalVue from '~src/create-local-vue'
22
import Vuex from 'vuex'
33
import VueRouter from 'vue-router'
44
import mount from '~src/mount'
55
import Component from '~resources/components/component.vue'
66

7-
describe('scopedVue', () => {
7+
describe('createLocalVue', () => {
88
it('installs Vuex without polluting global Vue', () => {
9-
const instance = scopedVue()
10-
instance.use(Vuex)
9+
const localVue = createLocalVue()
10+
localVue.use(Vuex)
1111
const store = new Vuex.Store({
1212
state: {
1313
test: 0
@@ -18,22 +18,22 @@ describe('scopedVue', () => {
1818
}
1919
}
2020
})
21-
const wrapper = mount(Component, { instance, store })
21+
const wrapper = mount(Component, { localVue, store })
2222
expect(wrapper.vm.$store).to.be.an('object')
2323
const freshWrapper = mount(Component)
2424
expect(typeof freshWrapper.vm.$store).to.equal('undefined')
2525
})
2626

2727
it('installs Router without polluting global Vue', () => {
28-
const instance = scopedVue()
29-
instance.use(VueRouter)
28+
const localVue = createLocalVue()
29+
localVue.use(VueRouter)
3030
const routes = [
3131
{ path: '/foo', component: Component }
3232
]
3333
const router = new VueRouter({
3434
routes
3535
})
36-
const wrapper = mount(Component, { instance, router })
36+
const wrapper = mount(Component, { localVue, router })
3737
expect(wrapper.vm.$route).to.be.an('object')
3838
const freshWrapper = mount(Component)
3939
expect(typeof freshWrapper.vm.$route).to.equal('undefined')

test/integration/specs/mount/options/instance.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import Vue from 'vue'
22
import mount from '~src/mount'
33
import Component from '~resources/components/component.vue'
44

5-
describe('mount.instance', () => {
6-
it('mounts component using passed instance as base instance', () => {
7-
const ScopedVue = Vue.extend()
8-
ScopedVue.version = '2.3'
9-
const wrapper = mount(Component, { instance: ScopedVue, intercept: { test: true }})
5+
describe('mount.localVue', () => {
6+
it('mounts component using passed localVue as base Vue', () => {
7+
const localVue = Vue.extend()
8+
localVue.version = '2.3'
9+
const wrapper = mount(Component, { localVue: localVue, intercept: { test: true }})
1010
expect(wrapper.vm.test).to.equal(true)
1111
const freshWrapper = mount(Component)
1212
expect(typeof freshWrapper.vm.test).to.equal('undefined')

test/integration/specs/shallow.spec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ import ComponentWithNestedChildren from '~resources/components/component-with-ne
99
import ComponentWithLifecycleHooks from '~resources/components/component-with-lifecycle-hooks.vue'
1010

1111
describe('shallow', () => {
12-
it('returns new VueWrapper of Vue instance if no options are passed', () => {
12+
it('returns new VueWrapper of Vue localVue if no options are passed', () => {
1313
const compiled = compileToFunctions('<div><input /></div>')
1414
const wrapper = shallow(compiled)
1515
expect(wrapper).to.be.instanceOf(VueWrapper)
1616
expect(wrapper.vm).to.be.an('object')
1717
})
1818

19-
it('returns new VueWrapper of Vue instance with all children stubbed', () => {
19+
it('returns new VueWrapper of Vue localVue with all children stubbed', () => {
2020
const wrapper = shallow(ComponentWithNestedChildren)
2121
expect(wrapper).to.be.instanceOf(VueWrapper)
2222
expect(wrapper.findAll(Component).length).to.equal(0)
2323
expect(wrapper.findAll(ComponentWithChildComponent).length).to.equal(1)
2424
})
2525

26-
it('returns new VueWrapper of Vue instance with all children stubbed', () => {
26+
it('returns new VueWrapper of Vue localVue with all children stubbed', () => {
2727
const wrapper = shallow(ComponentWithNestedChildren)
2828
expect(wrapper).to.be.instanceOf(VueWrapper)
2929
expect(wrapper.findAll(Component).length).to.equal(0)
@@ -37,15 +37,15 @@ describe('shallow', () => {
3737
expect(mountedWrapper.findAll(Component).length).to.equal(1)
3838
})
3939

40-
it('stubs globally registered components when options.instance is provided', () => {
41-
const freshVue = Vue.extend()
40+
it('stubs globally registered components when options.localVue is provided', () => {
41+
const localVue = Vue.extend()
4242
const log = sinon.stub(console, 'log')
43-
freshVue.component('registered-component', ComponentWithLifecycleHooks)
43+
localVue.component('registered-component', ComponentWithLifecycleHooks)
4444
const Component = {
4545
render: h => h('registered-component')
4646
}
47-
shallow(Component, { instance: freshVue })
48-
mount(Component, { instance: freshVue })
47+
shallow(Component, { localVue })
48+
mount(Component, { localVue })
4949

5050
expect(log.callCount).to.equal(4)
5151
log.restore()

0 commit comments

Comments
 (0)