Using vue-i18n (v8.25.0 with vue v2.6.14), until now I had all my translations in .ts files holding the JS objects:
import { LocaleMessages } from 'vue-i18n'
const translations: LocaleMessages = {
en: {
test: 'Test',
},
}
export default translations
Now, in order to better manage the translations, I switched to using .json files for the translation objects and importing these json files in the code.
So the en.json translation file is just
{
"test": "Test"
}
and it is imported in a .ts file using
import { LocaleMessages } from 'vue-i18n'
import translation from './en.json'
const translations: LocaleMessages = {
en: translation,
}
export default translations
Of course, I set
"resolveJsonModule": true, in tsconfig.json to make the json-Import work.
This works when serving the application - so the translations are correctly loaded.
But when executing unit tests using vue-cli-service test:unit, the translations are not loaded and the following warnings are logged:
[vue-i18n] Cannot translate the value of keypath 'test'. Use the value of keypath as default.
This causes some unit tests to fail that assert that the English translated value is there.
Until now, these tests ran successfully but since changing to json files, this no longer works.
I guess, somehow jest does not load the json imports correctly. Is there anything I need to adjust to make jest also load the json translation files in test runs (an "equivalent" to resolveJsonModule: true)?