Skip to content

Commit b9b0aa9

Browse files
committed
refactor: rename intercept to mocks
1 parent f6bc715 commit b9b0aa9

14 files changed

+33
-29
lines changed

docs/.eslintrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"globals": {
1010
"mount": true,
1111
"shallow": true,
12-
"Component": true
12+
"Component": true,
13+
"MyPlugin": true
14+
},
15+
"rules": {
16+
"no-unused-vars": 0
1317
}
1418
}

docs/en/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
- [context](api/options.md#context)
1515
- [slots](api/options.md#slots)
1616
- [stubs](api/options.md#stubs)
17-
- [intercept](api/options.md#intercept)
17+
- [mocks](api/options.md#mocks)
1818
- [localVue](api/options.md#localvue)
1919
- [attachToDocument](api/options.md#attachtodocument)
2020
- [attrs](api/options.md#attrs)

docs/en/api/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- [context](./options.md#context)
77
- [slots](./options.md#slots)
88
- [stubs](./options.md#stubs)
9-
- [intercept](./options.md#intercept)
9+
- [mocks](./options.md#mocks)
1010
- [localVue](./options.md#localvue)
1111
- [attachToDocument](./options.md#attachtodocument)
1212
- [attrs](./options.md#attrs)

docs/en/api/createLocalVue.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Foo from './Foo.vue'
1717
const localVue = createLocalVue()
1818
const wrapper = shallow(Foo, {
1919
localVue,
20-
intercept: { foo: true }
20+
mocks: { foo: true }
2121
})
2222
expect(wrapper.vm.foo).to.equal(true)
2323

docs/en/api/mount.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('Foo', () => {
100100
it('renders a div', () => {
101101
const $route = { path: 'http://www.example-path.com' }
102102
const wrapper = mount(Foo, {
103-
intercept: {
103+
mocks: {
104104
$route
105105
}
106106
})

docs/en/api/options.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Vue options are passed to the component when a new instance is created. , e.g. `
99
- [context](#context)
1010
- [slots](#slots)
1111
- [stubs](#stubs)
12-
- [intercept](#intercept)
12+
- [mocks](#mocks)
1313
- [localVue](#localvue)
1414
- [attachToDocument](#attachtodocument)
1515
- [attrs](#attrs)
@@ -82,7 +82,7 @@ shallow(Component, {
8282
})
8383
```
8484

85-
### `intercept`
85+
### `mocks`
8686

8787
- type: `Object`
8888

@@ -95,7 +95,7 @@ import { expect } from 'chai'
9595

9696
const $route = { path: 'http://www.example-path.com' }
9797
const wrapper = shallow(Component, {
98-
intercept: {
98+
mocks: {
9999
$route
100100
}
101101
})
@@ -160,6 +160,6 @@ Set the component instance's `$listeners` object.
160160

161161
Clones component before mounting if `true`, which avoids mutating the original component definition.
162162

163-
`options.intercept` (`Object`): Add globals to Vue instance.
163+
`options.mocks` (`Object`): Add globals to Vue instance.
164164

165165
`options.localVue` (`Object`): vue class to use in `mount`. See [createLocalVue](createLocalVue.md)

docs/en/api/shallow.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- `{Object} slots`
1010
- `{Array<Componet|Object>|Component|String} default`
1111
- `{Array<Componet|Object>|Component|String} named`
12-
- `{Object} intercept`
12+
- `{Object} mocks`
1313
- `{Object|Array<string>} stubs`
1414
- `{boolean} clone`
1515
- `{Object} children`
@@ -114,7 +114,7 @@ describe('Foo', () => {
114114
it('renders a div', () => {
115115
const $route = { path: 'http://www.example-path.com' }
116116
const wrapper = shallow(Foo, {
117-
intercept: {
117+
mocks: {
118118
$route
119119
}
120120
})

flow/options.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
declare type Options = { // eslint-disable-line no-undef
22
attachToDocument?: boolean,
3-
intercept?: Object,
3+
mocks?: Object,
44
slots?: Object,
55
localVue?: Component,
66
stubs?: Object,

src/lib/add-intercepts.js

-7
This file was deleted.

src/lib/add-mocks.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @flow
2+
3+
export default function addMocks (mockedProperties: Object, Vue: Component) {
4+
Object.keys(mockedProperties).forEach((key) => {
5+
Vue.prototype[key] = mockedProperties[key]
6+
})
7+
}

src/lib/create-instance.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import Vue from 'vue'
44
import addSlots from './add-slots'
5-
import addIntercepts from './add-intercepts'
5+
import addMocks from './add-mocks'
66
import addAttrs from './add-attrs'
77
import addListeners from './add-listeners'
88
import addProvide from './add-provide'
@@ -44,8 +44,8 @@ export default function createConstructor (component: Component, options: Option
4444

4545
const Constructor = vue.extend(component)
4646

47-
if (options.intercept) {
48-
addIntercepts(options.intercept, Constructor)
47+
if (options.mocks) {
48+
addMocks(options.mocks, Constructor)
4949
}
5050

5151
const vm = new Constructor(options)

test/unit/specs/mount/options/localVue.js renamed to test/unit/specs/mount/options/localVue.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('mount.localVue', () => {
66
it('mounts component using passed localVue as base Vue', () => {
77
const localVue = Vue.extend()
88
localVue.version = '2.3'
9-
const wrapper = mount(Component, { localVue: localVue, intercept: { test: true }})
9+
const wrapper = mount(Component, { localVue: localVue, mocks: { 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/unit/specs/mount/options/intercept.spec.js renamed to test/unit/specs/mount/options/mocks.spec.js

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

4-
describe('mount.intercept', () => {
5-
it('adds variables to vm when passed as intercept object', () => {
4+
describe('mount.mocks', () => {
5+
it('adds variables to vm when passed as mocks object', () => {
66
const $store = { store: true }
77
const $route = { path: 'http://test.com' }
88
const wrapper = mount(Component, {
9-
intercept: {
9+
mocks: {
1010
$store,
1111
$route
1212
}
@@ -15,10 +15,10 @@ describe('mount.intercept', () => {
1515
expect(wrapper.vm.$route).to.equal($route)
1616
})
1717

18-
it('does not affect global vue class when passed as intercept object', () => {
18+
it('does not affect global vue class when passed as mocks object', () => {
1919
const $store = { store: true }
2020
const wrapper = mount(Component, {
21-
intercept: {
21+
mocks: {
2222
$store
2323
}
2424
})

types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ interface MountOptions<V extends Vue> extends ComponentOptions<V> {
8484
clone?: boolean
8585
context?: VNodeData
8686
localVue?: typeof Vue
87-
intercept?: object
87+
mocks?: object
8888
slots?: Slots
8989
stubs?: Stubs,
9090
attrs?: object

0 commit comments

Comments
 (0)