Though I have a working solution using the global object I'd love to avoid injection. Is there a way to use mocking to achieve this?
This is only about the mocking so the code is stripped down to only show this step.
//myComponent.vue
<template>
<div>{{$t('some.label')}}</div>
</template>
<script lang="ts">
import {defineComponent} from "vue"
export default defineComponent({
inject: ['$t'],
setup(){},
})
</script>
This one works.
//test
import myComponent from '../myComponent'
import { createI18n } from 'vue-i18n'
const i18n = createI18n({locale: 'en'})
const t = i18n.global.tm
const globalProvide = {
global: {
provide: {
$t: t
}
}
}
mount(myComponent, globalProvide)
This one doesen't. this.$t is not a function.
//test
import myComponent from '../myComponent'
mount(myComponent, {
mocks: {
$t: (msg) => { msg }
}
})