Skip to content

Commit b4717b7

Browse files
committed
[docs][zh-cn] update to 528d637
1 parent 528d637 commit b4717b7

18 files changed

+82
-66
lines changed

docs/zh-cn/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Vue Test Utils 是 Vue.js 官方的单元测试实用工具库。
1717
* [配合 Vuex 实用](guides/using-with-vuex.md)
1818
* [API](api/README.md)
1919
* [mount](api/mount.md)
20-
* [shallow](api/shallow.md)
20+
* [shallowMount](api/shallowMount.md)
2121
* [render](api/render.md)
2222
* [renderToString](api/renderToString.md)
2323
* [挂载选项](api/options.md)

docs/zh-cn/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
 * [配合 Vuex 使用](guides/using-with-vuex.md)
1414
* [API](api/README.md)
1515
* [mount](api/mount.md)
16-
* [shallow](api/shallow.md)
16+
* [shallowMount](api/shallowMount.md)
1717
* [render](api/render.md)
1818
* [renderToString](api/renderToString.md)
1919
* [挂载选项](api/options.md)

docs/zh-cn/api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# API
22

33
* [mount](./mount.md)
4-
* [shallow](./shallow.md)
4+
* [shallowMount](./shallowMount.md)
55
* [render](./render.md)
66
* [renderToString](./renderToString.md)
77
* [挂载选项](./options.md)

docs/zh-cn/api/config.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Vue Test Utils 包含了一个定义其选项的配置对象。
1515
存储在 `config.stubs` 中的存根会被默认使用。
1616
用到的组件存根。它们会被传入挂载选项的 `stubs` 覆写。
1717

18-
当把 `stubs` 作为一个数组传入挂载选项时,`config.stubs` 会被转换为一个数组,然后用只返回一个 `<!---->` 的基础组件进行存根。
18+
当把 `stubs` 作为一个数组传入挂载选项时,`config.stubs` 会被转换为一个数组,然后用只返回一个 `<${component name}-stub>` 的基础组件进行存根。
1919

2020
示例:
2121

@@ -79,3 +79,18 @@ VueTestUtils.config.provide['$logger'] = {
7979
}
8080
}
8181
```
82+
83+
### `logModifiedComponents`
84+
85+
- 类型:`Boolean`
86+
- 默认值:`true`
87+
88+
当被展开的子元素被自动化存根的时候记录下告警日志。设置为 `false` 时则会隐藏告警日志。和其它配置选项不同的是,它不能设置在挂载选项上。
89+
90+
示例:
91+
92+
```js
93+
import VueTestUtils from '@vue/test-utils'
94+
95+
VueTestUtils.config.logModifiedComponents = false
96+
```

docs/zh-cn/api/createLocalVue.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
可通过 `options.localVue` 来使用:
1111

1212
```js
13-
import { createLocalVue, shallow } from '@vue/test-utils'
13+
import { createLocalVue, shallowMount } from '@vue/test-utils'
1414
import Foo from './Foo.vue'
1515

1616
const localVue = createLocalVue()
17-
const wrapper = shallow(Foo, {
17+
const wrapper = shallowMount(Foo, {
1818
localVue,
1919
mocks: { foo: true }
2020
})
2121
expect(wrapper.vm.foo).toBe(true)
2222

23-
const freshWrapper = shallow(Foo)
23+
const freshWrapper = shallowMount(Foo)
2424
expect(freshWrapper.vm.foo).toBe(false)
2525
```
2626

docs/zh-cn/api/options.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 挂载选项
22

3-
`mount``shallow` 的选项。该对象同时包含了 Vue Test Utils 挂载选项和其它选项。
3+
`mount``shallowMount` 的选项。该对象同时包含了 Vue Test Utils 挂载选项和其它选项。
44

55
## Vue Test Utils 特定的挂载选项
66

@@ -50,7 +50,7 @@ expect(wrapper.is(Component)).toBe(true)
5050
import Foo from './Foo.vue'
5151
import Bar from './Bar.vue'
5252

53-
const wrapper = shallow(Component, {
53+
const wrapper = shallowMount(Component, {
5454
slots: {
5555
default: [Foo, Bar],
5656
fooBar: Foo, // 将会匹配 `<slot name="FooBar" />`。
@@ -88,7 +88,7 @@ There are three limitations.
8888
示例:
8989

9090
```js
91-
const wrapper = shallow(Component, {
91+
const wrapper = shallowMount(Component, {
9292
scopedSlots: {
9393
foo: '<p slot-scope="props">{{props.index}},{{props.text}}</p>'
9494
}
@@ -100,7 +100,7 @@ expect(wrapper.find('#fooWrapper').html()).toBe('<div id="fooWrapper"><p>0,text1
100100

101101
- 类型:`{ [name: string]: Component | boolean } | Array<string>`
102102

103-
将子组件存根。可以是一个要存根的组件名的数组或对象。如果 `stubs` 是一个数组,则每个存根都是一个 `<!---->`
103+
将子组件存根。可以是一个要存根的组件名的数组或对象。如果 `stubs` 是一个数组,则每个存根都是一个 `<${component name}-stub>`
104104

105105
示例:
106106

@@ -111,7 +111,7 @@ mount(Component, {
111111
stubs: ['registered-component']
112112
})
113113

114-
shallow(Component, {
114+
shallowMount(Component, {
115115
stubs: {
116116
// 使用一个特定的实现作为存根
117117
'registered-component': Foo,
@@ -131,7 +131,7 @@ shallow(Component, {
131131

132132
```js
133133
const $route = { path: 'http://www.example-path.com' }
134-
const wrapper = shallow(Component, {
134+
const wrapper = shallowMount(Component, {
135135
mocks: {
136136
$route
137137
}
@@ -207,7 +207,7 @@ expect(wrapper.vm.$route).toBeInstanceOf(Object)
207207

208208
## 其它选项
209209

210-
`mount``shallow` 的选项包含了挂载选项之外的选项时,则会将它们通过[扩展](https://vuejs.org/v2/api/#extends)覆写到其组件选项。
210+
`mount``shallowMount` 的选项包含了挂载选项之外的选项时,则会将它们通过[扩展](https://vuejs.org/v2/api/#extends)覆写到其组件选项。
211211

212212
```js
213213
const Component = {

docs/zh-cn/api/selectors.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ export default {
3232
```
3333

3434
```js
35-
import { shallow } from '@vue/test-utils'
35+
import { shallowMount } from '@vue/test-utils'
3636
import Foo from './Foo.vue'
3737

38-
const wrapper = shallow(Foo)
38+
const wrapper = shallowMount(Foo)
3939
expect(wrapper.is(Foo)).toBe(true)
4040
```
4141

docs/zh-cn/api/shallow.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `shallow(component {, options}])`
1+
# `shallowMount(component {, options}])`
22

33
- **参数:**
44

@@ -27,12 +27,12 @@
2727
**无选项:**
2828

2929
```js
30-
import { shallow } from '@vue/test-utils'
30+
import { shallowMount } from '@vue/test-utils'
3131
import Foo from './Foo.vue'
3232

3333
describe('Foo', () => {
3434
it('返回一个 div', () => {
35-
const wrapper = shallow(Foo)
35+
const wrapper = shallowMount(Foo)
3636
expect(wrapper.contains('div')).toBe(true)
3737
})
3838
})
@@ -41,12 +41,12 @@ describe('Foo', () => {
4141
**使用 Vue 选项:**
4242

4343
```js
44-
import { shallow } from '@vue/test-utils'
44+
import { shallowMount } from '@vue/test-utils'
4545
import Foo from './Foo.vue'
4646

4747
describe('Foo', () => {
4848
it('渲染一个 div', () => {
49-
const wrapper = shallow(Foo, {
49+
const wrapper = shallowMount(Foo, {
5050
propsData: {
5151
color: 'red'
5252
}
@@ -59,12 +59,12 @@ describe('Foo', () => {
5959
**固定在 DOM 上:**
6060

6161
```js
62-
import { shallow } from '@vue/test-utils'
62+
import { shallowMount } from '@vue/test-utils'
6363
import Foo from './Foo.vue'
6464

6565
describe('Foo', () => {
6666
it('渲染一个 div', () => {
67-
const wrapper = shallow(Foo, {
67+
const wrapper = shallowMount(Foo, {
6868
attachToDocument: true
6969
})
7070
expect(wrapper.contains('div')).toBe(true)
@@ -75,14 +75,14 @@ describe('Foo', () => {
7575
**默认的和具名的插槽:**
7676

7777
```js
78-
import { shallow } from '@vue/test-utils'
78+
import { shallowMount } from '@vue/test-utils'
7979
import Foo from './Foo.vue'
8080
import Bar from './Bar.vue'
8181
import FooBar from './FooBar.vue'
8282

8383
describe('Foo', () => {
8484
it('renders a div', () => {
85-
const wrapper = shallow(Foo, {
85+
const wrapper = shallowMount(Foo, {
8686
slots: {
8787
default: [Bar, FooBar],
8888
fooBar: FooBar, // Will match <slot name="FooBar" />,
@@ -97,13 +97,13 @@ describe('Foo', () => {
9797
**将全局属性存根:**
9898

9999
```js
100-
import { shallow } from '@vue/test-utils'
100+
import { shallowMount } from '@vue/test-utils'
101101
import Foo from './Foo.vue'
102102

103103
describe('Foo', () => {
104104
it('renders a div', () => {
105105
const $route = { path: 'http://www.example-path.com' }
106-
const wrapper = shallow(Foo, {
106+
const wrapper = shallowMount(Foo, {
107107
mocks: {
108108
$route
109109
}

docs/zh-cn/api/wrapper-array/at.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
- **示例:**
1111

1212
```js
13-
import { shallow } from '@vue/test-utils'
13+
import { shallowMount } from '@vue/test-utils'
1414
import Foo from './Foo.vue'
1515

16-
const wrapper = shallow(Foo)
16+
const wrapper = shallowMount(Foo)
1717
const divArray = wrapper.findAll('div')
1818
const secondDiv = divArray.at(1)
1919
expect(secondDiv.is('p')).toBe(true)

docs/zh-cn/api/wrapper-array/contains.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
- **示例:**
1313

1414
```js
15-
import { shallow } from '@vue/test-utils'
15+
import { shallowMount } from '@vue/test-utils'
1616
import Foo from './Foo.vue'
1717
import Bar from './Bar.vue'
1818

19-
const wrapper = shallow(Foo)
19+
const wrapper = shallowMount(Foo)
2020
const divArray = wrapper.findAll('div')
2121
expect(divArray.contains('p')).toBe(true)
2222
expect(divArray.contains(Bar)).toBe(true)

docs/zh-cn/api/wrapper-array/filter.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
- **示例:**
1515

1616
```js
17-
import { shallow } from '@vue/test-utils'
17+
import { shallowMount } from '@vue/test-utils'
1818
import Foo from './Foo.vue'
1919

20-
const wrapper = shallow(Foo)
20+
const wrapper = shallowMount(Foo)
2121
const filteredDivArray = wrapper.findAll('div').filter(w => !w.hasClass('filtered'))
2222
```

docs/zh-cn/api/wrapper/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ Vue Test Utils 是一个基于包裹器的 API。
88

99
`vm` `Component`:这是该 Vue 实例。你可以通过 `wrapper.vm` 访问一个实例所有的[方法和属性](https://vuejs.org/v2/api/#Instance-Properties)。这只存在于 Vue 组件包裹器中
1010
`element` `HTMLElement`:包裹器的根 DOM 节点
11-
`options` `Object`:一个对象,包含传递给 `mount``shallow` 的 Vue Test Utils 选项
12-
`options.attachedToDom` `Boolean`:如果 `attachToDom` 传递给了 `mount``shallow` 则为真
11+
`options` `Object`:一个对象,包含传递给 `mount``shallowMount` 的 Vue Test Utils 选项
12+
`options.attachedToDocument` `Boolean`:如果 `attachToDom` 传递给了 `mount``shallowMount` 则为真
13+
`options.sync` `Boolean`:如果 `sync` 没有以 `false` 传递给了 `mount``shallowMount` 则为真
1314

1415
- **方法:**
1516

docs/zh-cn/guides/common-tips.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818

1919
额外的,对于包含许多子组件的组件来说,整个渲染树可能会非常大。重复渲染所有的子组件可能会让我们的测试变慢。
2020

21-
Vue Test Utils 允许你通过 `shallow` 方法只挂载一个组件而不渲染其子组件 (即保留它们的存根):
21+
Vue Test Utils 允许你通过 `shallowMount` 方法只挂载一个组件而不渲染其子组件 (即保留它们的存根):
2222

2323
```js
24-
import { shallow } from '@vue/test-utils'
24+
import { shallowMount } from '@vue/test-utils'
2525

26-
const wrapper = shallow(Component) // 返回一个包裹器,包含一个挂载的组件实例
26+
const wrapper = shallowMount(Component) // 返回一个包裹器,包含一个挂载的组件实例
2727
wrapper.vm // 挂载的 Vue 实例
2828
```
2929

docs/zh-cn/guides/testing-SFCs-with-karma.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ export default {
106106

107107
```js
108108
import { expect } from 'chai'
109-
import { shallow } from '@vue/test-utils'
109+
import { shallowMount } from '@vue/test-utils'
110110
import Counter from '../src/Counter.vue'
111111

112112
describe('Counter.vue', () => {
113113
it('increments count when button is clicked', () => {
114-
const wrapper = shallow(Counter)
114+
const wrapper = shallowMount(Counter)
115115
wrapper.find('button').trigger('click')
116116
expect(wrapper.find('div').text()).contains('1')
117117
})

docs/zh-cn/guides/testing-SFCs-with-mocha-webpack.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ export default {
150150
然后创建一个名为 `test/Counter.spec.js` 的测试文件并写入如下代码:
151151

152152
```js
153-
import { shallow } from '@vue/test-utils'
153+
import { shallowMount } from '@vue/test-utils'
154154
import Counter from '../src/Counter.vue'
155155

156156
describe('Counter.vue', () => {
157157
it('计数器在点击按钮时自增', () => {
158-
const wrapper = shallow(Counter)
158+
const wrapper = shallowMount(Counter)
159159
wrapper.find('button').trigger('click')
160160
expect(wrapper.find('div').text()).toMatch('1')
161161
})

docs/zh-cn/guides/testing-async-components.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ export default {
4444
测试用例可以写成像这样:
4545

4646
``` js
47-
import { shallow } from 'vue-test-utils'
47+
import { shallowMount } from 'vue-test-utils'
4848
import Foo from './Foo'
4949
jest.mock('axios')
5050

5151
test('Foo', () => {
5252
it('fetches async when a button is clicked', () => {
53-
const wrapper = shallow(Foo)
53+
const wrapper = shallowMount(Foo)
5454
wrapper.find('button').trigger('click')
5555
expect(wrapper.vm.value).toBe('value')
5656
})
@@ -62,7 +62,7 @@ test('Foo', () => {
6262
``` js
6363
test('Foo', () => {
6464
it('fetches async when a button is clicked', (done) => {
65-
const wrapper = shallow(Foo)
65+
const wrapper = shallowMount(Foo)
6666
wrapper.find('button').trigger('click')
6767
wrapper.vm.$nextTick(() => {
6868
expect(wrapper.vm.value).toBe('value')
@@ -79,14 +79,14 @@ test('Foo', () => {
7979
The updated test looks like this:
8080

8181
``` js
82-
import { shallow } from 'vue-test-utils'
82+
import { shallowMount } from 'vue-test-utils'
8383
import flushPromises from 'flush-promises'
8484
import Foo from './Foo'
8585
jest.mock('axios')
8686

8787
test('Foo', () => {
8888
it('fetches async when a button is clicked', async () => {
89-
const wrapper = shallow(Foo)
89+
const wrapper = shallowMount(Foo)
9090
wrapper.find('button').trigger('click')
9191
await flushPromises()
9292
expect(wrapper.vm.value).toBe('value')

0 commit comments

Comments
 (0)