You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/zh/guides/common-tips.md
+17-22
Original file line number
Diff line number
Diff line change
@@ -29,47 +29,42 @@ wrapper.vm // 挂载的 Vue 实例
29
29
30
30
### 生命周期钩子
31
31
32
+
<divclass="vueschool"style="margin-top:1em;"><ahref="https://vueschool.io/lessons/learn-how-to-test-vuejs-lifecycle-methods?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn how to use Vue Test Utils to test Vue.js Lifecycle Hooks with Vue School">在 Vue School 学习如何测试生命周期方法及其区间</a></div>
Copy file name to clipboardExpand all lines: docs/zh/guides/dom-events.md
+2-4
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
## 测试键盘、鼠标等其它 DOM 事件
2
2
3
+
<divclass="vueschool"><ahref="https://vueschool.io/lessons/traversing-the-dom?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn to traverse and interact with the DOM with a free video lesson from Vue School">在 Vue School 免费学习如何遍历 DOM 并与其互动的课程</a></div>
Copy file name to clipboardExpand all lines: docs/zh/guides/getting-started.md
+32-11
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
## 起步
2
2
3
+
<divclass="vueschool"><ahref="https://vueschool.io/lessons/installing-vue-test-utils?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn how to get started with Vue Test Utils, Jest, and testing Vue Components with Vue School">学习如何用 Vue Test Utils、Jest 起步并测试 Vue 组件</a></div>
4
+
3
5
### 安装
4
6
5
7
快速尝鲜 Vue Test Utils 的办法就是克隆我们的 demo 仓库再加上基本的设置和依赖安装。
@@ -10,6 +12,22 @@ cd vue-test-utils-getting-started
在 Vue 之外最常见的一种异步行为就是在 Vuex 中进行 API 调用。以下示例将展示如何测试在 Vuex 中进行 API 调用的方法。本示例使用 Jest 运行测试并模拟 HTTP 库`axios`。可以在[这里](https://jestjs.io/docs/en/manual-mocks.html#content)找到有关 Jest Mock 的更多信息。
37
50
38
-
`axios`Mock 的实现如下所示:
51
+
`axios`mock 的实现如下所示:
39
52
40
53
```js
41
54
exportdefault {
@@ -47,7 +60,7 @@ export default {
47
60
48
61
```html
49
62
<template>
50
-
<button@click="fetchResults" />
63
+
<button@click="fetchResults">{{ value }}</button>
51
64
</template>
52
65
53
66
<script>
@@ -75,12 +88,14 @@ export default {
75
88
```js
76
89
import { shallowMount } from'@vue/test-utils'
77
90
importFoofrom'./Foo'
78
-
jest.mock('axios')
91
+
jest.mock('axios', () => ({
92
+
get:Promise.resolve('value')
93
+
}))
79
94
80
95
it('fetches async when a button is clicked', () => {
81
96
constwrapper=shallowMount(Foo)
82
97
wrapper.find('button').trigger('click')
83
-
expect(wrapper.vm.value).toBe('value')
98
+
expect(wrapper.text()).toBe('value')
84
99
})
85
100
```
86
101
@@ -91,15 +106,15 @@ it('fetches async when a button is clicked', done => {
Copy file name to clipboardExpand all lines: docs/zh/guides/testing-single-file-components-with-jest.md
+10
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,18 @@
4
4
5
5
Jest 是一个由 Facebook 开发的测试运行器,致力于提供一个“bettery-included”单元测试解决方案。你可以在其[官方文档](https://jestjs.io/)学习到更多 Jest 的知识。
6
6
7
+
<divclass="vueschool"><ahref="https://vueschool.io/courses/learn-how-to-test-vuejs-components?friend=vuejs"target="_blank"rel="sponsored noopener"title="Learn how to use Jest and Vue Test Utils to test Single File Components with Vue School">在 Vue School 学习如何使用 Jest 测试单文件组件</a></div>
0 commit comments