-
-
Notifications
You must be signed in to change notification settings - Fork 861
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
Unit tests not working since introducing vue-i18n #276
Comments
You need to inject an i18n object when instantiating your component. Using your example : import Vue from 'vue'
import Home from '@/components/Home'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const i18n = new VueI18n({});
describe('Home.vue', () => {
it('should render correct contents', () => {
const Constructor = Vue.extend(Home)
const vm = new Constructor({i18n}).$mount()
expect(vm.$el.querySelector('h1').textContent)
.to.equal('Welcome to Server Client Project (STP)!')
})
}) Now it creates a new VueI18n object and pass it to |
I already solve it: https://stackoverflow.com/questions/48238906/vue-project-tests-are-failing-when-i-added-vue-i18n-karma-mocha-phantomjs/48239256#48239256 @bost-h and yes, you are right, I didn't inject the component. Thank you! |
Thanks @bost-h saved me a lot of time! |
@vsambor hello! import Vue from "vue";
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const vueI18n= new VueI18n()
import {mount} from '@vue/test-utils'
import Demo from '../../../src/components/Demo'
it('vue-i18n test', async () => {
const wrapper = mount(Demo, {
vueI18n,
})
// mount({ vueI18n, ...Demo}) not works too
}) As you can see we use mount(component, options) syntax. And get the same error
<template>
<div>
{{ $t('profile.lastName') }}
</div>
</template>
<script>
export default {
}
</script> |
Hi, First, create a js file wich will create your component with all your extensions, for example GenerateComponent.js
Then, call the function in your testing file
Hope it helps. |
Vue.prototype._i18n = i18n must be under the line App.mpType = 'app' App.mpType = 'app'
Vue.prototype._i18n = i18n |
thanks @bost-h, it works for me. |
I included internationalization in my project (I decided to use vue-i18n lib)
The translation works as expected, but when I run my unit tests, I have errors, note: The tests passed before adding vue-i18n.
My vue-i18n configuration (src/i18n/index.js):
The main.js:
This my component, which I test (Home.vue):
This is the test (Home.spec.js):
The errors I get:
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.072 secs / 0.007 secs)
I looked around for other similar problems, but I couldn't find a clear solution.
Thank you!
The text was updated successfully, but these errors were encountered: