diff --git a/docs/zh/api/options.md b/docs/zh/api/options.md index 7e09f3f15..c90c09c28 100644 --- a/docs/zh/api/options.md +++ b/docs/zh/api/options.md @@ -1,6 +1,13 @@ # 挂载选项 -即 `mount` 和 `shallowMount` 的选项。该对象同时包含了 Vue Test Utils 挂载选项和其它选项。 +`mount` 和 `shallowMount` 的选项。 + +:::tip +除了下方列出的选项,`options` 对象还可以包含任何 `new Vue ({ /*options here*/ })` 调用时的有效选项。 +当通过 `mount` / `shallowMount` 挂载时,这些选项将会合并入组件现有的选项中。 + +[查阅其它选项的例子](#其它选项) +::: - [`context`](#context) - [`slots`](#slots) @@ -199,6 +206,8 @@ expect(wrapper.vm.$route).toBeInstanceOf(Object) 当设为 `true` 时,组件在渲染时将会挂载到 DOM 上。 +如果添加到了 DOM 上,你应该在测试的最后调用 `wrapper.destroy()` 将元素从文档中移除并销毁组件实例。 + ## attrs - 类型:`Object` diff --git a/docs/zh/api/wrapper/destroy.md b/docs/zh/api/wrapper/destroy.md index 2136b1156..74e585d8a 100644 --- a/docs/zh/api/wrapper/destroy.md +++ b/docs/zh/api/wrapper/destroy.md @@ -17,3 +17,7 @@ mount({ }).destroy() expect(spy.calledOnce).toBe(true) ``` + +如果挂载时 `attachToDocument` 被设为 `true`,则组件的 DOM 元素也将会从文档中被移除。 + +对于函数式组件来说,`destroy` 只会从文档中移除渲染出来的 DOM 元素。 diff --git a/docs/zh/guides/testing-single-file-components-with-jest.md b/docs/zh/guides/testing-single-file-components-with-jest.md index cec861e4a..c224ec3c0 100644 --- a/docs/zh/guides/testing-single-file-components-with-jest.md +++ b/docs/zh/guides/testing-single-file-components-with-jest.md @@ -155,7 +155,7 @@ Jest 可以被用来生成多种格式的测试覆盖率报告。以下是一个 ### 测试规范示例 -如果你已经熟悉了 Jasmine,你应该很适应 Jest 的[断言 API](https://jestjs.io/docs/zh-Hans/expect.htm): +如果你已经熟悉了 Jasmine,你应该很适应 Jest 的[断言 API](https://jestjs.io/docs/zh-Hans/expect): ```js import { mount } from '@vue/test-utils'