Skip to content

Commit f102a9a

Browse files
cloneDeep not that deep (#1504)
* 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 <[email protected]>
1 parent f3d0d3f commit f102a9a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Diff for: docs/guides/using-with-vuex.md

+8
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,14 @@ test('updates "evenOrOdd" getter when "increment" is committed', () => {
376376

377377
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.
378378

379+
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:
380+
381+
```js
382+
import myModule from './myModule'
383+
// ...
384+
const store = new Vuex.Store({ modules: { myModule: cloneDeep(myModule) } })
385+
```
386+
379387
### Resources
380388

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

0 commit comments

Comments
 (0)