From 587faeb6f86ca952eb3e0371119d93ee80d13017 Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Tue, 21 Jul 2020 22:05:09 +1000 Subject: [PATCH 1/3] docs: vuex --- src/guide/vuex.md | 165 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 162 insertions(+), 3 deletions(-) diff --git a/src/guide/vuex.md b/src/guide/vuex.md index a8c7f28..9086bda 100644 --- a/src/guide/vuex.md +++ b/src/guide/vuex.md @@ -1,5 +1,164 @@ -# Vuex +## Testing Vuex -:) +Vuex is just an implementation detail; no special treatment is required for testing components using Vuex. That said, there are some techniques that might make your tests easier to read and write. We will look at those here. -https://github.com/vuejs/vue-test-utils-next-docs/issues/8 \ No newline at end of file +This guide you assumed you are familiar with Vuex. Vuex 4 is the version that works with Vue.js 3. Read the docs [here](https://vuex.vuejs.org/). + +## A Simple Example + +Here is a simple Vuex store, and a component that relies on a Vuex store been present: + +```js +import { createStore } from 'vuex' + +const store = createStore({ + state() { + return { + count: 0 + } + }, + mutations: { + increment(state: any) { + state.count += 1 + } + } +}) +``` + +The store simply stores a count, increasing it when the `increment` mutation is committed. This is the component we will be testing: + +```js +const App = { + template: ` +
+
+ `, + computed: { + count() { + return this.$store.state.count + } + }, + methods: { + increment() { + this.$store.commit('increment') + } + } +} +``` + +## Testing with a Real Vuex Store + +To full test this component (and the Vuex store) are working, we will click on the `