Skip to content

Commit

Permalink
cloneDeep not that deep (#1504)
Browse files Browse the repository at this point in the history
* cloneDeep not that deep

To save others hours of headaches, a small update for testing running Vuex store with modules.

* docs: add syntax

Co-authored-by: Lachlan <lachlan.miller.1990@outlook.com>
  • Loading branch information
andreipopovici and lmiller1990 committed Apr 13, 2020
1 parent f3d0d3f commit f102a9a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/guides/using-with-vuex.md
Expand Up @@ -376,6 +376,14 @@ test('updates "evenOrOdd" getter when "increment" is committed', () => {

Notice that we use `cloneDeep` to clone the store config before creating a store with it. This is because Vuex mutates the options object used to create the store. To make sure we have a clean store in each test, we need to clone the `storeConfig` object.

However, `cloneDeep` is not "deep" enough to also clone store modules. If your `storeConfig` includes modules, you need to pass an object to `new Vuex.Store()`, like so:

```js
import myModule from './myModule'
// ...
const store = new Vuex.Store({ modules: { myModule: cloneDeep(myModule) } })
```

### Resources

- [Example project for testing the components](https://github.com/eddyerburgh/vue-test-utils-vuex-example)
Expand Down

0 comments on commit f102a9a

Please sign in to comment.