From 12783ea659f6d350452c38075fc3bc0fad017a4f Mon Sep 17 00:00:00 2001 From: Andrei Popovici Date: Sun, 12 Apr 2020 19:01:25 +0300 Subject: [PATCH 1/2] cloneDeep not that deep To save others hours of headaches, a small update for testing running Vuex store with modules. --- 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..9f2631b6b 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: + +``` +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) From 65d9944a062584ef308aed8160b88ed505ab0bfe Mon Sep 17 00:00:00 2001 From: Lachlan Date: Mon, 13 Apr 2020 10:15:58 +1000 Subject: [PATCH 2/2] docs: add syntax --- docs/guides/using-with-vuex.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guides/using-with-vuex.md b/docs/guides/using-with-vuex.md index 9f2631b6b..d33a94f45 100644 --- a/docs/guides/using-with-vuex.md +++ b/docs/guides/using-with-vuex.md @@ -378,9 +378,9 @@ Notice that we use `cloneDeep` to clone the store config before creating a store 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) } }) ```