Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da7a2cb

Browse filesBrowse files
Jinjiangeddyerburgh
authored andcommitted
docs(zh): keep update (vuejs#662)
1 parent 19239c2 commit da7a2cb
Copy full SHA for da7a2cb
Expand file treeCollapse file tree

20 files changed

+87
-144
lines changed

‎docs/zh/README.md

Copy file name to clipboardExpand all lines: docs/zh/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Vue Test Utils
1+
# 介绍
22

33
Vue Test Utils 是 Vue.js 官方的单元测试实用工具库。
44

‎docs/zh/SUMMARY.md

Copy file name to clipboardExpand all lines: docs/zh/SUMMARY.md
-74Lines changed: 0 additions & 74 deletions
This file was deleted.

‎docs/zh/api/README.md

Copy file name to clipboardExpand all lines: docs/zh/api/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
!!!include(docs/zh/api/renderToString.md)!!!
77
!!!include(docs/zh/api/selectors.md)!!!
88
!!!include(docs/zh/api/createLocalVue.md)!!!
9-
!!!include(docs/zh/api/config.md)!!!
9+
!!!include(docs/zh/api/config.md)!!!

‎docs/zh/api/config.md

Copy file name to clipboardExpand all lines: docs/zh/api/config.md
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Vue Test Utils 包含了一个定义其选项的配置对象。
44

5+
### Vue Test Utils 配置选项
6+
57
### `stubs`
68

79
- 类型:`Object`
@@ -13,7 +15,7 @@ Vue Test Utils 包含了一个定义其选项的配置对象。
1315
存储在 `config.stubs` 中的存根会被默认使用。
1416
用到的组件存根。它们会被传入挂载选项的 `stubs` 覆写。
1517

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

1820
示例:
1921

@@ -77,3 +79,18 @@ VueTestUtils.config.provide['$logger'] = {
7779
}
7880
}
7981
```
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/api/createLocalVue.md

Copy file name to clipboardExpand all lines: docs/zh/api/createLocalVue.md
+3-3Lines 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/api/options.md

Copy file name to clipboardExpand all lines: docs/zh/api/options.md
+7-9Lines changed: 7 additions & 9 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
- [`context`](#context)
66
- [`slots`](#slots)
@@ -48,7 +48,7 @@ expect(wrapper.is(Component)).toBe(true)
4848
import Foo from './Foo.vue'
4949
import Bar from './Bar.vue'
5050

51-
const wrapper = shallow(Component, {
51+
const wrapper = shallowMount(Component, {
5252
slots: {
5353
default: [Foo, Bar],
5454
fooBar: Foo, // 将会匹配 `<slot name="FooBar" />`。
@@ -86,7 +86,7 @@ There are three limitations.
8686
示例:
8787

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

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

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

103103
示例:
104104

@@ -109,7 +109,7 @@ mount(Component, {
109109
stubs: ['registered-component']
110110
})
111111

112-
shallow(Component, {
112+
shallowMount(Component, {
113113
stubs: {
114114
// 使用一个特定的实现作为存根
115115
'registered-component': Foo,
@@ -129,7 +129,7 @@ shallow(Component, {
129129

130130
```js
131131
const $route = { path: 'http://www.example-path.com' }
132-
const wrapper = shallow(Component, {
132+
const wrapper = shallowMount(Component, {
133133
mocks: {
134134
$route
135135
}
@@ -198,14 +198,12 @@ expect(wrapper.vm.$route).toBeInstanceOf(Object)
198198
- 类型:`boolean`
199199
- 默认值:`true`
200200

201-
将所有的侦听器都设置为同步执行。
202-
203201
`sync``true` 时,这个 Vue 组件会被同步渲染。
204202
`sync``false` 时,这个 Vue 组件会被异步渲染。
205203

206204
## 其它选项
207205

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

210208
```js
211209
const Component = {

‎docs/zh/api/selectors.md

Copy file name to clipboardExpand all lines: docs/zh/api/selectors.md
+2-2Lines 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/api/wrapper-array/README.md

Copy file name to clipboardExpand all lines: docs/zh/api/wrapper-array/README.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
一个 `WrapperArray` 是一个包含 [`Wrapper`](../wrapper/README.md) 数组以及 `Wrapper` 的测试方法等对象。
44

5-
- **属性:**
5+
## 属性
66

77
### `wrappers`
88

99
`array`: 包含在 `WrapperArray` 内的 `Wrappers`
1010

11-
###`length`
11+
### `length`
1212

1313
`number`:该 `WrapperArray` 中包含的 `Wrapper` 的数量。
1414

15-
- **方法:**
15+
## 方法
1616

1717
!!!include(docs/zh/api/wrapper-array/at.md)!!!
1818
!!!include(docs/zh/api/wrapper-array/contains.md)!!!
@@ -24,4 +24,4 @@
2424
!!!include(docs/zh/api/wrapper-array/setData.md)!!!
2525
!!!include(docs/zh/api/wrapper-array/setMethods.md)!!!
2626
!!!include(docs/zh/api/wrapper-array/setProps.md)!!!
27-
!!!include(docs/zh/api/wrapper-array/trigger.md)!!!
27+
!!!include(docs/zh/api/wrapper-array/trigger.md)!!!

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

Copy file name to clipboardExpand all lines: docs/zh/api/wrapper-array/at.md
+2-2Lines 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/api/wrapper-array/contains.md

Copy file name to clipboardExpand all lines: docs/zh/api/wrapper-array/contains.md
+2-2Lines 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/api/wrapper-array/filter.md

Copy file name to clipboardExpand all lines: docs/zh/api/wrapper-array/filter.md
+2-2Lines 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/api/wrapper/README.md

Copy file name to clipboardExpand all lines: docs/zh/api/wrapper/README.md
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
## Wrapper
1+
# Wrapper
22

33
Vue Test Utils 是一个基于包裹器的 API。
44

55
一个 `Wrapper` 是一个包括了一个挂载组件或 vnode,以及测试该组件或 vnode 的方法。
66

7-
- **属性:**
7+
## 属性
88

99
### `vm`
1010

11-
`Component`:这是该 Vue 实例。你可以通过 `wrapper.vm` 访问一个实例所有的[方法和属性](https://vuejs.org/v2/api/#Instance-Properties)
12-
13-
这只存在于 Vue 组件包裹器中
11+
`Component`:这是该 Vue 实例。你可以通过 `wrapper.vm` 访问一个实例所有的[方法和属性](https://vuejs.org/v2/api/#Instance-Properties)。这只存在于 Vue 组件包裹器中。
1412

1513
### `element`
1614

1715
`HTMLElement`:包裹器的根 DOM 节点
1816

1917
### `options`
2018

21-
`Object`:一个对象,包含传递给 `mount``shallow` 的 Vue Test Utils 选项
22-
2319
#### `options.attachedToDom`
2420

25-
`Boolean`:如果 `attachToDom` 传递给了 `mount``shallow` 则为真
21+
`Boolean`:如果 `attachToDom` 传递给了 `mount``shallowMount` 则为真
22+
23+
#### `options.sync`
24+
25+
`Boolean`:如果挂载选项里的 `sync` 不是 `false` 则为真
2626

27-
- **方法:**
27+
## 方法
2828

2929
!!!include(docs/zh/api/wrapper/attributes.md)!!!
3030
!!!include(docs/zh/api/wrapper/classes.md)!!!

‎docs/zh/api/wrapper/emitted.md

Copy file name to clipboardExpand all lines: docs/zh/api/wrapper/emitted.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ expect(wrapper.emitted('foo').length).toBe(2)
4444
expect(wrapper.emitted('foo')[1]).toEqual([123])
4545
```
4646

47-
该 `.emitted() 方法每次被调用时都返回相同的对象,而不是返回一个新的,所以当新事件被触发时该对象会被更新:
47+
`.emitted()` 方法每次被调用时都返回相同的对象,而不是返回一个新的,所以当新事件被触发时该对象会被更新:
4848

4949
```js
5050
const emitted = wrapper.emitted()

‎docs/zh/api/wrapper/setData.md

Copy file name to clipboardExpand all lines: docs/zh/api/wrapper/setData.md
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## setData(data)
22

3-
设置 `Wrapper` `vm` 的属性并强制更新。
3+
设置 `Wrapper` `vm` 的属性。
4+
5+
`setData` 通过合并现有的属性生效,被覆写的数组除外。
46

57
**注意:该包裹器必须包含一个 Vue 示例。**
68

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

Copy file name to clipboardExpand all lines: docs/zh/guides/common-tips.md
+3-3Lines 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/guides/testing-SFCs-with-karma.md

Copy file name to clipboardExpand all lines: docs/zh/guides/testing-SFCs-with-karma.md
+2-2Lines 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/guides/testing-SFCs-with-mocha-webpack.md

Copy file name to clipboardExpand all lines: docs/zh/guides/testing-SFCs-with-mocha-webpack.md
+2-2Lines 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
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.