Testing implementation of plugin with Jest
See original GitHub issueI’m trying to test vuex-i18n with jest, so we can test it is configured correctly and the correct strings are being generated and retrieved.
Here is what I’ve added in the test files: `const localVue = createLocalVue() localVue.use(Vuex)
let store = new Vuex.Store() localVue.use(VuexI18n, store) localVue.i18n.add(‘en’, en)`
where en
is an imported translation file. I’ve also been using vue-test-utils.
This is the error I get when trying to run the test:
`TypeError: Cannot read property 'add' of undefined`
I’ve checked and I’ve used this method to test other plugins so not sure why this way isn’t working.
Any ideas?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Watch Plugins - Jest
The Jest watch plugin system provides a way to hook into specific parts of Jest and to define watch mode menu prompts that...
Read more >Testing with Jest - Backstage.io
Jest is a Facebook-built unit testing framework specifically built for React. It follows in the footsteps of other classic Node.js unit testing-related ...
Read more >How To: Write Jest tests for plugins · Reaction Docs
We use and recommend plugin authors to use Jest for writing tests for their plugins. Consider the following module.js file:
Read more >Jest testing: Top features and how to use them - LogRocket Blog
Jest is a JavaScript testing framework built by Facebook and primarily designed for React-based applications, but is also used with Babel, ...
Read more >Easy JavaScript unit tests in WordPress with Jest - StartFunction
So Jest is a great and simple solution to write tests that cover the JavaScript code of our WordPress plugins or themes. But...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I almost forgot about this 😃 Updating with what I’ve managed to put together here There were some limitations with what can be tested which I will try to explain either the repo, or in this thread when I get around to it
Hi @HumayraHanif
First of all thank you for taking the time to implement some real testing. We did not yet get around to it and where simply using manual testing, with the files located in the test folder.
With
import vuexI18n from "vuex-i18n"
you will get an object with the propertiesstore
andplugin
. Please make sure that you use thevuexi18n.plugin
to initialize the plugin, not the complete object imported from vuexi18n – i.e.localVue.use(VuexI18n.plugin, store)