Thanks for taking a look.
I'm trying to run automated tests on my Vuex-backed application and am having trouble diagnosing why committing a mutation in a Mocha testfile results in a warning from Vuex saying that I'm directly modifying the state, even though it's modified within a mutation. I use Vuex to keep track of the global state and render certain elements based on the global state (e.g. show buttonA if state.status === 'INITIAL'
, show buttonB if state.status === 'LOADING'
).
For example, I have a central store with: state = { status: 'INITIAL' };
Then I have a corresponding mutation:
'LOADING': (state) => {
state.status = 'LOADING';
},
Then if I commit changes normally through a component or through a store action it works fine: this.$store.commit('INITIAL');
However, if I try to establish the same Vuex store and commit the same changes in a Mocha test file, it gives the error:
'[Vue warn]: Error in callback for watcher "function () { return this._data.$$state; }": "Error: [vuex] Do not mutate vuex store state outside mutation handlers."
The mutation occurs correctly and the tests pass smoothly, but it gives me this warning at the point when the mutation sets: state.status = 'LOADING';
I have tried moving sending the commit request to within an action, but that did not resolve the issue. I've tried changing where the store/Vue are declared, but that did not resolve the issue. I've tried setting strict: false
for the store, but that didn't resolve the issue nor even hide it.
I don't feel like I'm doing something that abnormal in wanting to test commits as such, but I may be totally off-base. Please let me know if I need to provide more information, the error dump, or an example repo.
Thanks! Keith