diff --git a/docs/.vitepress/config/index.mts b/docs/.vitepress/config/index.mts index e3fe97898..ad9c16ffe 100644 --- a/docs/.vitepress/config/index.mts +++ b/docs/.vitepress/config/index.mts @@ -10,6 +10,6 @@ export default defineConfig({ locales: { root: { label: 'English', lang: 'en-US', link: '/', ...enConfig }, fr: { label: 'Français', lang: 'fr-FR', link: '/fr/', ...frConfig }, - zh: { label: '简体中文 (校对中)', lang: 'zh-CN', link: '/zh/', ...zhConfig } + zh: { label: '简体中文', lang: 'zh-CN', link: '/zh/', ...zhConfig } } }) diff --git a/docs/.vitepress/config/zh.mts b/docs/.vitepress/config/zh.mts index 3e3b0d194..fd24b3a25 100644 --- a/docs/.vitepress/config/zh.mts +++ b/docs/.vitepress/config/zh.mts @@ -114,7 +114,7 @@ export const zhConfig: LocaleSpecificConfig = { link: '/zh/guide/advanced/teleport' }, { - text: 'Stubs 和浅挂载', + text: '测试替身 (stub) 和浅挂载', link: '/zh/guide/advanced/stubs-shallow-mount' }, { diff --git a/docs/.vitepress/theme/index.mts b/docs/.vitepress/theme/index.mts index 30162d817..716b55a15 100644 --- a/docs/.vitepress/theme/index.mts +++ b/docs/.vitepress/theme/index.mts @@ -5,7 +5,7 @@ import status from '../translation-status.json' import './custom.css' const i18nLabels = { fr: 'La traduction est synchronisée avec les docs du ${date} dont le hash du commit est ${hash}.', - zh: '该翻译已同步到了 ${date} 的版本,其对应的 commit hash 是 ${hash}
同时该文档仍处于校对中,如有任何疑问或想参与校对工作,请移步这里了解更多。' + zh: '该翻译已同步到了 ${date} 的版本,其对应的 commit hash 是 ${hash}。' } diff --git a/docs/zh/api/index.md b/docs/zh/api/index.md index 6e3184ec3..badcc0e8b 100644 --- a/docs/zh/api/index.md +++ b/docs/zh/api/index.md @@ -716,7 +716,7 @@ test('global.renderStubDefaultSlot', () => { #### global.stubs -在挂载的组件上使用全局替代组件 (stub)。 +在挂载的组件上使用全局测试替身 (stub)。 **签名:** @@ -726,7 +726,7 @@ stubs?: Record **详细信息:** -默认情况下,`Transition` 和 `TransitionGroup` 组件会被自动 stub 掉。 +默认情况下,`Transition` 和 `TransitionGroup` 组件会被自动创建测试替身。 `Component.vue`: @@ -788,7 +788,7 @@ test('global.stubs using a custom component', () => { ### shallow -组件的所有子组件替换为 stub。 +组件的所有子组件替换为测试替身。 **签名:** @@ -1893,7 +1893,7 @@ function shallowMount(Component, options?: MountingOptions): VueWrapper **详细信息:** -`shallowMount` 的行为与 `mount` 完全相同,但它默认会 stub (替代) 所有的子组件。实际上,`shallowMount(Component)` 是 `mount(Component, { shallow: true })` 的别名。 +`shallowMount` 的行为与 `mount` 完全相同,但它默认为所有的子组件创建测试替身。实际上,`shallowMount(Component)` 是 `mount(Component, { shallow: true })` 的别名。 ## enableAutoUnmount diff --git a/docs/zh/guide/advanced/stubs-shallow-mount.md b/docs/zh/guide/advanced/stubs-shallow-mount.md index f145808ed..5f548be12 100644 --- a/docs/zh/guide/advanced/stubs-shallow-mount.md +++ b/docs/zh/guide/advanced/stubs-shallow-mount.md @@ -84,7 +84,7 @@ test('stubs component', () => { 这将为整个渲染树中的*所有* `` 组件创建测试替身,而不管它们出现在哪个层级。这就是为什么它在 `global` 挂载选项中的原因。 ::: tip -要桩化组件,你可以使用 `components` 中的键或组件的名称。如果在 `global.stubs` 中同时给出这两者,将优先使用键。 +要为组件创建测试替身,你可以使用 `components` 中的键或组件的名称。如果在 `global.stubs` 中同时给出这两者,将优先使用键。 ::: ## 为所有子组件创建测试替身 diff --git a/docs/zh/guide/advanced/transitions.md b/docs/zh/guide/advanced/transitions.md index bb6d157ae..2cfb88ba4 100644 --- a/docs/zh/guide/advanced/transitions.md +++ b/docs/zh/guide/advanced/transitions.md @@ -40,7 +40,7 @@ export default { ``` -由于 Vue Test Utils 会模拟内置的过渡效果,你可以像测试其他组件一样测试上述组件: +由于 Vue Test Utils 会为内置的 transition 组件创建测试替身,你可以像测试其他组件一样测试上述组件: ```js import Component from './Component.vue' @@ -60,11 +60,11 @@ test('works with transitions', async () => { ## 部分支持 -Vue Test Utils 内置的过渡效果模拟比较简单,并不涵盖 Vue 所有的[过渡特性](https://vuejs.org/guide/built-ins/transition)。例如它不支持 [JavaScript 钩子](https://vuejs.org/guide/built-ins/transition#javascript-hooks)。这一限制可能会导致 Vue 发出警告。 +Vue Test Utils 内置的 transition 组件的测试替身比较简单,并不涵盖 Vue 所有的[过渡特性](https://vuejs.org/guide/built-ins/transition)。例如它不支持 [JavaScript 钩子](https://vuejs.org/guide/built-ins/transition#javascript-hooks)。这一限制可能会导致 Vue 发出警告。 ::: tip 潜在解决方案: -- 你可以通过将 [global stubs transition](../../api/#global-stubs) 设置为 false 来关闭自动模拟。 -- 如果需要,你可以自行模拟过渡效果,以处理这些钩子。 +- 你可以通过将[全局 transition 测试替身](../../api/#global-stubs) 设置为 false 来停止自从创建测试替身。 +- 如果需要,你可以自行创建 transition 的测试替身,以处理这些钩子。 - 你可以在测试中捕获警告以消除它。 ::: diff --git a/docs/zh/guide/faq/index.md b/docs/zh/guide/faq/index.md index 12a6ac6a1..63e1a2853 100644 --- a/docs/zh/guide/faq/index.md +++ b/docs/zh/guide/faq/index.md @@ -26,6 +26,6 @@ TypeError: Cannot set property prefix of # which has only a getter **可能的解决方案** -1. 使用 `mount` 而不是 `shallowMount` 进行不带存根的渲染 +1. 使用 `mount` 而不是 `shallowMount` 进行不带测试替身的渲染 2. 通过模拟 `console.warn` 来忽略警告 3. 重命名 prop,以避免与 `Element` 属性冲突 diff --git a/docs/zh/migration/index.md b/docs/zh/migration/index.md index 800333641..65d3d3fa4 100644 --- a/docs/zh/migration/index.md +++ b/docs/zh/migration/index.md @@ -1,12 +1,12 @@ # 从 Vue Test Utils v1 迁移 -对 VTU v1 到 VTU v2 的更改进行回顾,并提供一些代码片段以展示所需的修改。如果你遇到未在此处记录的错误或行为差异,请[提交问题](https://github.com/vuejs/test-utils/issues/new)。 +这是一篇对 VTU v1 到 VTU v2 变更的回顾,并提供一些代码片段以展示所需的修改。如果你遇到了未在此处记录的错误或行为差异,请[创建 issue](https://github.com/vuejs/test-utils/issues/new)。 -## 更改 +## 变更 -### `propsData` 现在是 `props` +### `propsData` 现已改为 `props` -在 VTU v1 中,你使用 `propsData` 挂载选项传递 props。这令人困惑,因为你在 Vue 组件的 `props` 选项中声明 props。现在你可以使用 `props` 挂载选项传递 `props`。为了向后兼容,`propsData` 仍然被支持。 +在 VTU v1 中,你可以通过挂载选项 `propsData` 传递 props。这令人困惑,因为你在 Vue 组件中声明 props 时使用的是 `props`。现在你可以通过挂载选项 `props` 传递 `props` 了。同时为了向后兼容,`propsData` 仍然是支持的。 **之前**: @@ -38,11 +38,11 @@ const wrapper = mount(App, { ### 不再需要 `createLocalVue` -在 Vue 2 中,插件通常会修改全局 Vue 实例并将各种方法附加到原型上。从 Vue 3 开始,这种情况不再存在 - 你使用 `createApp` 创建新的 Vue 应用,而不是 `new Vue`,并使用 `createApp(App).use(/* ... */)` 安装插件。 +在 Vue 2 中,插件通常会修改全局 Vue 实例并将各种方法附加到其原型上。从 Vue 3 开始,这种情况不再存在,我们通过 `createApp` 创建新的 Vue 应用,而不是 `new Vue`,并使用 `createApp(App).use(/* ... */)` 安装插件。 -为了避免在 Vue Test Utils v1 中污染全局 Vue 实例,我们提供了 `createLocalVue` 函数和 `localVue` 挂载选项。这使你可以为每个测试拥有一个独立的 Vue 实例,避免跨测试污染。在 Vue 3 中,这不再是问题,因为插件、混入等不会修改全局 Vue 实例。 +在 Vue Test Utils v1 中,为了避免污染全局 Vue 实例的情况,我们提供了 `createLocalVue` 函数和 `localVue` 挂载选项。这使你可以为每个测试提供一个独立的 Vue 实例,避免不同测试之间污染。在 Vue 3 中,这不再是问题,因为插件、mixin 等不会修改全局 Vue 实例。 -在大多数情况下,你之前使用 `createLocalVue` 和 `localVue` 挂载选项来安装插件、混入或指令,现在可以使用 [`global` 挂载选项](/api/#global)。以下是一个使用 `localVue` 的组件和测试示例,以及它现在的样子 (使用 `global.plugins`,因为 Vuex 是一个插件): +在大多数情况下,你之前使用 `createLocalVue` 和 `localVue` 挂载选项来安装插件、mixin 或指令,现在可以使用 [`global` 挂载选项](/api/#global)。以下是一个之前使用 `localVue` 的组件和测试示例,以及它现在的样子 (利用了 `global.plugins`,因为 Vuex 是一个插件): **之前**: @@ -145,7 +145,7 @@ const wrapper = mount(App, { ### `shallowMount` 和 `renderStubDefaultSlot` -`shallowMount` 旨在存根任何自定义组件。虽然在 Vue Test Utils v1 中是这样的,但存根组件仍会渲染其默认的 ``。虽然这并非预期的行为,但一些用户对此功能表示喜欢。在 v2 中,这一行为已被修正 - **桩组件的插槽内容不再渲染**。 +`shallowMount` 旨在将某个自定义组件置换为测试替身。虽然在 Vue Test Utils v1 中是这样的,但被置换的组件仍会渲染其默认的 ``。虽然这并非预期的行为,但一些用户对此功能表示喜欢。在 v2 中,这一行为已被修正,**组件测试替身的插槽内容不再被渲染**。 给定以下代码: @@ -209,17 +209,17 @@ import { config } from '@vue/test-utils' config.global.renderStubDefaultSlot = true ``` -### `destroy` 现在是 `unmount` 以匹配 Vue 3 +### `destroy` 现已改为 `unmount` 以匹配 Vue 3 -Vue 3 将 `vm.$destroy` 重命名为 `vm.$unmount`。Vue Test Utils 也随之更改;`wrapper.destroy()` 现在是 `wrapper.unmount()`。 +Vue 3 将 `vm.$destroy` 重命名为 `vm.$unmount`。Vue Test Utils 也随之更改;`wrapper.destroy()` 现已改为 `wrapper.unmount()`。 -### `scopedSlots` 现在与 `slots` 合并 +### `scopedSlots` 和 `slots` 现已合并 -Vue 3 将 `slot` 和 `scoped-slot` 语法统一为单一语法 `v-slot`,你可以在[文档](https://v3.vuejs.org/guide/migration/slots-unification.html#overview)中阅读相关内容。由于 `slot` 和 `scoped-slot` 现在合并,因此 `scopedSlots` 挂载选项现在已弃用 - 只需使用 `slots` 挂载选项即可。 +Vue 3 将 `slot` 和 `scoped-slot` 语法统一为单一语法 `v-slot`,你可以在[文档](https://v3.vuejs.org/guide/migration/slots-unification.html#overview)中阅读相关内容。由于 `slot` 和 `scoped-slot` 现已合并,因此 `scopedSlots` 挂载选项现已被弃用,只需使用 `slots` 挂载选项即可。 -### `slots` 的作用域现在作为 `params` 暴露 +### `slots` 的作用域现在暴露为 `params` -当使用字符串模板作为插槽内容时,如果没有使用 `