From f102a9a35e280f7afe6c1b62a5df7090ebdd6f98 Mon Sep 17 00:00:00 2001 From: Andrei Popovici Date: Mon, 13 Apr 2020 03:16:43 +0300 Subject: [PATCH] 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 --- docs/guides/using-with-vuex.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/guides/using-with-vuex.md b/docs/guides/using-with-vuex.md index 12206d2a6..d33a94f45 100644 --- a/docs/guides/using-with-vuex.md +++ b/docs/guides/using-with-vuex.md @@ -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)