File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 1
1
# 挂载选项
2
2
3
- 即 ` mount ` 和 ` shallowMount ` 的选项。该对象同时包含了 Vue Test Utils 挂载选项和其它选项。
3
+ ` mount ` 和 ` shallowMount ` 的选项。
4
+
5
+ ::: tip
6
+ 除了下方列出的选项,` options ` 对象还可以包含任何 ` new Vue ({ /*options here*/ }) ` 调用时的有效选项。
7
+ 当通过 ` mount ` / ` shallowMount ` 挂载时,这些选项将会合并入组件现有的选项中。
8
+
9
+ [ 查阅其它选项的例子] ( #其它选项 )
10
+ :::
4
11
5
12
- [ ` context ` ] ( #context )
6
13
- [ ` slots ` ] ( #slots )
@@ -199,6 +206,8 @@ expect(wrapper.vm.$route).toBeInstanceOf(Object)
199
206
200
207
当设为 ` true ` 时,组件在渲染时将会挂载到 DOM 上。
201
208
209
+ 如果添加到了 DOM 上,你应该在测试的最后调用 ` wrapper.destroy() ` 将元素从文档中移除并销毁组件实例。
210
+
202
211
## attrs
203
212
204
213
- 类型:` Object `
Original file line number Diff line number Diff line change @@ -17,3 +17,7 @@ mount({
17
17
}).destroy ()
18
18
expect (spy .calledOnce ).toBe (true )
19
19
```
20
+
21
+ 如果挂载时 ` attachToDocument ` 被设为 ` true ` ,则组件的 DOM 元素也将会从文档中被移除。
22
+
23
+ 对于函数式组件来说,` destroy ` 只会从文档中移除渲染出来的 DOM 元素。
Original file line number Diff line number Diff line change @@ -155,7 +155,7 @@ Jest 可以被用来生成多种格式的测试覆盖率报告。以下是一个
155
155
156
156
### 测试规范示例
157
157
158
- 如果你已经熟悉了 Jasmine,你应该很适应 Jest 的[ 断言 API] ( https://jestjs.io/docs/zh-Hans/expect.htm ) :
158
+ 如果你已经熟悉了 Jasmine,你应该很适应 Jest 的[ 断言 API] ( https://jestjs.io/docs/zh-Hans/expect ) :
159
159
160
160
``` js
161
161
import { mount } from ' @vue/test-utils'
You can’t perform that action at this time.
0 commit comments