So just need to create a local view, use your Pina vplugin and before each test case, create the testing Pina, passing the initial state and find the store. And then when mounting the component, you need to pass local view and Pina too. So, quick recap getters in Vue.js 2 and Jest are not writable. So you need to set the correct state in order to make them work as expected. So like this, if you want to set store count, you can write it or just patch the store if you need to update more properties at once. You can migrate your tests like this.
So moving create store and importing create testing Pina and new store. Removing the create store from Vuex and using create testing Pina. And again, importing the longer plugin Pina in the shallow mount and test everything like this. Same for VJSU, just import what you need, define your store instead of the Vuex store and pass it to the shallow function or mount function and everything should work. Well, yes, not exactly. So there are a couple migration problems. Let's call them migration knots.
So if you were using the store with a direct approach like this, now you need to import your store and access properties and getters using the store and no more store magic usage. Same for commit and dispatch. If you were using commit and dispatch from everywhere in your application, now you need to import store and call the current function, action function. Then another thing you need to remember is that if you are using store in this way outside of scripts tab, well, please remember not to write this in the root of your module, otherwise you can get this error because you don't have ActivePynea defined. So remember to prep it in a function and use it like that or use it in the scripts tab.
You may ask if Vuex and Pynea can coexist. Well, yes, of course, but when migrating, please remember to migrate entire modules and not entire components. So you need to make sure that a single module has been migrated before moving to another module just for order and simplicity of migration. So they can coexist, but you have just a single module from Vuex and that module can be migrated to Pynea, but other modules can be on Vuex while migrating. If you need store persistence, you can use it in this way in two ways, really, because you can subscribe to your store changes and set your, for example, local storage in your preferred way, and you can restore it when the application has been refreshed using mystore.state and settings.state, or you can watch. You can use a watcher in your application and watch for Pinion state changes and store them in a local storage variable, for example. And if you need to restore it, you can use pinion.state.value and set its value.
Now we reached the end of our migration. As final tasks, we need to remove Vuex from main.js. So just remove your import and your store usage. And then we can delete Vuex store and tests. And last but not least, we need to uninstall Vuex dependencies. So Vuex and for example, Vue CLI plugin Vuex. And that's it, we immigrated from Vuex to Pinia. Now I leave you a couple of links to of course the official documentation for Pinia and two repositories with moving to Pinia branch, so you can check and see what you need or you may want change for migrating from Vuex to Pinia.
Comments