Skip to content

Commit

Permalink
docs(zh): update (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinjiang authored and eddyerburgh committed Dec 9, 2018
1 parent 5500553 commit 9cbf908
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions docs/zh/guides/common-tips.md
Expand Up @@ -58,6 +58,56 @@ expect(wrapper.emitted().foo[1]).toEqual([123])

你也可以调用 [`wrapper.emittedByOrder()`](../api/wrapper/emittedByOrder.md) 获取一个按触发先后排序的事件数组。

### 从子组件触发事件

你可以通过访问子组件实例来触发一个自定义事件

**待测试的组件**

```html
<template>
<div>
<child-component @custom="onCustom"/>
<p v-if="emitted">触发!</p>
</div>
</template>

<script>
import ChildComponent from './ChildComponent'
export default {
name: 'ParentComponent',
components: { ChildComponent },
data() {
return {
emitted: false
}
},
methods: {
onCustom () {
this.emitted = true
}
}
}
</script>
```

**测试代码**

```js
import { shallowMount } from '@vue/test-utils'
import ParentComponent from '@/components/ParentComponent'
import ChildComponent from '@/components/ChildComponent'

describe('ParentComponent', () => {
it("displays 'Emitted!' when custom event is emitted", () => {
const wrapper = shallowMount(ParentComponent)
wrapper.find(ChildComponent).vm.$emit('custom')
expect(wrapper.html()).toContain('Emitted!')
})
})
```

### 操作组件状态

你可以在包裹器上用 `setData``setProps` 方法直接操作组件状态:
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/guides/using-with-vuex.md
Expand Up @@ -95,7 +95,7 @@ describe('Actions.vue', () => {

这里发生了什么?首先我们用 `localVue.use` 方法告诉 Vue 使用 Vuex。这只是 `Vue.use` 的一个包裹器。

然后我们用 `new Vuex.store` 伪造了一个 store 并填入假数据。我们只把它传递给 action,因为我们只关心这个。
然后我们用 `new Vuex.Store` 伪造了一个 store 并填入假数据。我们只把它传递给 action,因为我们只关心这个。

该 action 是 [Jest 伪造函数](https://facebook.github.io/jest/docs/en/mock-functions.html)。这些伪造函数让我们去断言该 action 是否被调用。

Expand Down

0 comments on commit 9cbf908

Please sign in to comment.