Skip to content

Commit 1ca4225

Browse files
authored
docs(zh): review extending-vtu (#2583)
* docs(zh): review community-learning * docs(zh): review extending-vtu/plugins
1 parent fd31749 commit 1ca4225

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

docs/zh/guide/extending-vtu/community-learning.md

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

33
- [Vue 3 Testing Handbook](https://lmiller1990.github.io/vue-testing-handbook/v3/)。在线指南。
44
- [Become a Ninja with Vue 3](https://books.ninja-squad.com/vue)。电子书和在线课程。
5-
- [Vue.js 3:The Composition API](https://vuejs-course.com/composition-api)。在线课程 (包括测试模块)。
5+
- [Vue.js 3:The Composition API](https://vuejs-course.com/composition-api)。在线课程 (包括一个测试模块)。
66
- [Testing Vue 3 apps with Vue Test Utils](https://www.youtube.com/playlist?list=PLC2LZCNWKL9ahK1IoODqYxKu5aA9T5IOA)。视频播放列表。
77
- [Testing Vue.js Components](https://vueschool.io/courses/learn-how-to-test-vuejs-components?friend=vth)。在线课程。
88
- [Front-end Testing and a tale of three users](https://afontcu.dev/frontend-testing-code-consumers/)。博客文章。

docs/zh/guide/extending-vtu/plugins.md

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# 插件
22

3-
插件为 Vue Test Utils 的 API 添加了全局功能。这是扩展 Vue Test Utils API 的官方方式,可以添加自定义逻辑、方法或功能
3+
插件为 Vue Test Utils 的 API 添加全局功能。这是为 Vue Test Utils API 扩展自定义逻辑、方法或功能的官方方式
44

55
插件的使用场景:
66

77
1. 为现有的公共方法创建别名
8-
2. 将匹配器附加到 Wrapper 实例
9-
3. 将功能附加到 Wrapper
8+
2. Wrapper 实例添加匹配器
9+
3. Wrapper 添加功能
1010

1111
## Wrapper 插件
1212

1313
### 使用插件
1414

1515
通过调用 `config.plugins.VueWrapper.install()` 方法来安装插件。这必须在调用 `mount` 之前完成。
1616

17-
`install()` 方法将接收一个 `WrapperAPI` 实例,该实例包含该实例的公共和私有属性
17+
`install()` 方法将接收一个 `WrapperAPI` 实例及其公共和私有属性
1818

1919
```js
2020
// setup.js file
@@ -33,15 +33,15 @@ config.plugins.VueWrapper.install(MyPlugin)
3333
config.plugins.VueWrapper.install(MyPlugin, { someOption: true })
3434
```
3535

36-
你的插件应该只安装一次。如果你使用 Jest,这应该在你的 Jest 配置的 `setupFiles``setupFilesAfterEnv` 文件中。
36+
你的插件应该只安装一次。如果你使用 Jest,它应该在你的 Jest 配置的 `setupFiles``setupFilesAfterEnv` 文件中。
3737

38-
某些插件在导入时会自动调用 `config.plugins.VueWrapper.install()`。如果它们同时扩展多个接口,这是常见的情况。请遵循你正在安装的插件的说明。
38+
某些插件会在导入时自动调用 `config.plugins.VueWrapper.install()`。如果它们同时扩展多个接口,这是常见的情况。请遵循你正在安装的插件的说明。
3939

40-
查看 [Vue Community Guide](https://vue-community.org/guide/ecosystem/testing.html)[awesome-vue](https://github.com/vuejs/awesome-vue#test) 获取社区贡献的插件和库的集合
40+
查阅 [Vue Community Guide](https://vue-community.org/guide/ecosystem/testing.html)[awesome-vue](https://github.com/vuejs/awesome-vue#test) 获取社区贡献的插件和库
4141

4242
### 编写插件
4343

44-
Vue Test Utils 插件只是一个函数,该函数接收挂载的 `VueWrapper``DOMWrapper` 实例,并可以对其进行修改。
44+
Vue Test Utils 插件只是一个单纯的函数,该函数接收挂载的 `VueWrapper``DOMWrapper` 实例,并可以对其进行修改。
4545

4646
#### 基本插件
4747

@@ -53,7 +53,7 @@ import { config } from '@vue/test-utils'
5353

5454
const myAliasPlugin = (wrapper) => {
5555
return {
56-
$el: wrapper.element // 简单别名
56+
$el: wrapper.element // 简单的别名
5757
}
5858
}
5959

@@ -62,9 +62,7 @@ const myAliasPlugin = (wrapper) => {
6262
config.plugins.VueWrapper.install(myAliasPlugin)
6363
```
6464

65-
在你的测试中,你将能够在 `mount` 之后使用你的插件。
66-
67-
// component.spec.js
65+
在测试中,你可以在 `mount` 之后使用该插件。
6866

6967
```js
7068
// component.spec.js
@@ -74,7 +72,7 @@ console.log(wrapper.$el.innerHTML) // 🔌 Plugin
7472

7573
#### 数据测试 ID 插件
7674

77-
下面的插件为 `VueWrapper` 实例添加了一个 `findByTestId` 方法。这鼓励使用依赖于 Vue 组件上的测试专用属性的选择器策略
75+
下面的插件为 `VueWrapper` 实例添加了一个 `findByTestId` 方法。它鼓励你在 Vue 组件上选择测试转用的 attribute 作为你的选择器策略
7876

7977
用法:
8078

@@ -92,7 +90,7 @@ console.log(wrapper.$el.innerHTML) // 🔌 Plugin
9290

9391
```js
9492
const wrapper = mount(MyComponent)
95-
wrapper.findByTestId('name-input') // returns a VueWrapper or DOMWrapper
93+
wrapper.findByTestId('name-input') // 返回一个 VueWrapper DOMWrapper
9694
```
9795

9896
插件的实现:
@@ -115,14 +113,14 @@ const DataTestIdPlugin = (wrapper) => {
115113
config.plugins.VueWrapper.install(DataTestIdPlugin)
116114
```
117115

118-
## Stubs 插件
116+
## Stub 插件
119117

120-
`config.plugins.createStubs` 允许覆盖 VTU 提供的默认桩创建
118+
`config.plugins.createStubs` 允许覆盖 VTU 默认创建并提供的测试替身
121119

122120
一些使用场景包括:
123121

124-
- 你想在桩中添加更多逻辑 (例如命名插槽)
125-
- 你想为多个组件使用不同的桩 (例如从库中桩化组件)
122+
* 你想在测试替身中添加更多逻辑 (例如具名插槽)
123+
* 你想为多个组件使用不同的测试替身 (例如一个库中的测试替身组件)
126124

127125
### 用法
128126

@@ -134,7 +132,7 @@ config.plugins.createStubs = ({ name, component }) => {
134132
}
135133
```
136134

137-
每当 VTU 生成一个桩时,这个函数都会被调用,无论是通过以下方式
135+
不论通过以下哪种方式,每当 VTU 生成一个测试替身时,这个函数都会被调用:
138136

139137
```typescript
140138
const wrapper = mount(Component, {
@@ -146,13 +144,13 @@ const wrapper = mount(Component, {
146144
})
147145
```
148146

149-
还是
147+
150148

151149
```typescript
152150
const wrapper = shallowMount(Component)
153151
```
154152

155-
但当你显式设置桩时,它将不会被调用:
153+
但当你显式设置测试替身时,它将不会被调用:
156154

157155
```typescript
158156
const wrapper = mount(Component, {
@@ -164,9 +162,9 @@ const wrapper = mount(Component, {
164162
})
165163
```
166164

167-
## 使用 TypeScript 的插件
165+
## 配合 TypeScript 使用插件
168166

169-
要使用自定义的 Wrapper 插件与 [TypeScript](https://www.typescriptlang.org/) 一起使用,你必须声明你的自定义 wrapper 函数。因此,添加一个名为 `vue-test-utils.d.ts` 的文件,内容如下
167+
要结合 [TypeScript](https://www.typescriptlang.org/) 使用自定义的包装器插件,你必须声明你的自定义包装器函数。即基于几下内容添加一个名为 `vue-test-utils.d.ts` 的文件:
170168

171169
```typescript
172170
import { DOMWrapper } from '@vue/test-utils'
@@ -180,4 +178,4 @@ declare module '@vue/test-utils' {
180178

181179
## 推广你的插件
182180

183-
如果你缺少某些功能,可以考虑编写插件来扩展 Vue Test Utils,并提交以在 [Vue Community Guide](https://vue-community.org/guide/ecosystem/testing.html)[awesome-vue](https://github.com/vuejs/awesome-vue#test) 中推广。
181+
如果你需要某些功能,可以考虑编写插件来扩展 Vue Test Utils,并提交以在 [Vue Community Guide](https://vue-community.org/guide/ecosystem/testing.html)[awesome-vue](https://github.com/vuejs/awesome-vue#test) 中推广。

0 commit comments

Comments
 (0)