Skip to content

Commit af88abb

Browse files
38elementseddyerburgh
authored andcommitted
docs: add other options to docs/en/api/options.md (#252)
* Add other options to docs/en/api/options.md * Update test/unit/specs/mount.spec.js * Fix docs/en/api/options.md
1 parent 940484e commit af88abb

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

docs/en/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- [listeners](api/options.md#listeners)
2828
- [clone](api/options.md#clone)
2929
- [provide](api/options.md#provide)
30+
- [other options](api/options.md#other-options)
3031
* [Wrapper](api/wrapper/README.md)
3132
* [attributes](api/wrapper/attributes.md)
3233
* [classes](api/wrapper/classes.md)

docs/en/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [listeners](api/options.md#listeners)
2424
- [clone](api/options.md#clone)
2525
- [provide](api/options.md#provide)
26+
- [other options](api/options.md#other-options)
2627
* [Wrapper](api/wrapper/README.md)
2728
* [attributes](api/wrapper/attributes.md)
2829
* [classes](api/wrapper/classes.md)

docs/en/api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [listeners](./options.md#listeners)
1414
- [clone](./options.md#clone)
1515
- [provide](./options.md#provide)
16+
- [other options](./options.md#other-options)
1617
* [Wrapper](./wrapper/README.md)
1718
* [attributes](./wrapper/attributes.md)
1819
* [classes](./wrapper/classes.md)

docs/en/api/options.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Mounting Options
22

3-
Options for `mount` and `shallow`. The options object can contain both `vue-test-utils` mounting options and raw Vue options.
4-
5-
Vue options are passed to the component when a new instance is created. , e.g. `store`, `propsData`. For a full list, see the [Vue API docs](https://vuejs.org/v2/api/).
3+
Options for `mount` and `shallow`. The options object can contain both `vue-test-utils` mounting options and other options.
64

75
## `vue-test-utils` Specific Mounting Options
86

@@ -166,3 +164,33 @@ Clones component before mounting if `true`, which avoids mutating the original c
166164
- type: `Object`
167165

168166
Pass properties for components to use in injection. See [provide/inject](https://vuejs.org/v2/api/#provide-inject).
167+
168+
## Other options
169+
170+
When the options for `mount` and `shallow` contain the options other than the mounting options, the component options are overwritten with those using [extends](https://vuejs.org/v2/api/#extends).
171+
172+
```js
173+
const Component = {
174+
template: '<div>{{ foo() }}{{ bar() }}{{ baz() }}</div>',
175+
methods: {
176+
foo () {
177+
return 'a'
178+
},
179+
bar () {
180+
return 'b'
181+
}
182+
}
183+
}
184+
const options = {
185+
methods: {
186+
bar () {
187+
return 'B'
188+
},
189+
baz () {
190+
return 'C'
191+
}
192+
}
193+
}
194+
const wrapper = mount(Component, options)
195+
expect(wrapper.text()).to.equal('aBC')
196+
```

test/unit/specs/mount.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,30 @@ describe('mount', () => {
148148
const fn = () => mount(TestComponent)
149149
expect(fn).to.throw()
150150
})
151+
152+
it('overwrites the component options with the options other than the mounting options when the options for mount contain those', () => {
153+
const Component = {
154+
template: '<div>{{ foo() }}{{ bar() }}{{ baz() }}</div>',
155+
methods: {
156+
foo () {
157+
return 'a'
158+
},
159+
bar () {
160+
return 'b'
161+
}
162+
}
163+
}
164+
const options = {
165+
methods: {
166+
bar () {
167+
return 'B'
168+
},
169+
baz () {
170+
return 'C'
171+
}
172+
}
173+
}
174+
const wrapper = mount(Component, options)
175+
expect(wrapper.text()).to.equal('aBC')
176+
})
151177
})

0 commit comments

Comments
 (0)