Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing implementation of plugin with Jest #82

Open
HumayraHanif opened this issue Jul 23, 2018 · 8 comments
Open

Testing implementation of plugin with Jest #82

HumayraHanif opened this issue Jul 23, 2018 · 8 comments
Labels

Comments

@HumayraHanif
Copy link

I'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?

@tikiatua
Copy link
Member

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 properties store and plugin. Please make sure that you use the vuexi18n.plugin to initialize the plugin, not the complete object imported from vuexi18n – i.e. localVue.use(VuexI18n.plugin, store)

@HumayraHanif
Copy link
Author

Thanks, I've had a bit more luck with getting something working, but there are some limitations. I'll share the code once I've got a bit further in case anyone else is looking for something similar.

@HumayraHanif
Copy link
Author

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

@tikiatua
Copy link
Member

HI @HumayraHanif

Thank you very much for sharing the testing setup. I will try to set this up for the repository together with some proper documentation in the upcoming weeks.

@cimbis
Copy link

cimbis commented Aug 16, 2019

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

Big thumbs up, this saved my day!

@tikiatua
Copy link
Member

Thank you for following up on this.

I am literally right now working on this for version 2 of the plugin. I just finished setting up the plugin with vue-cli, migrating the complete plugin code over to typescript and implementing the first unit tests with jest.

This will really help us to automate the testing and include a lot more test cases. I will try to make the version 2 branch available in a few hours. There will very likely be some breaking changes and new features, but the current version is just a migration to typescript.

@tikiatua
Copy link
Member

The version branch with a first example of a test is now available

@HumayraHanif
Copy link
Author

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

Big thumbs up, this saved my day!

I'm glad it helped! I have struggled with designing tests to work when the translation string needs parameters passed into it (e.g, "Hello {name}.") but for now have mocked the translation function to return the string as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants