Open
Description
I use vue-i18n in my component, which is written using script setup syntax. When I try to render component in my test I'm getting the error
TypeError: $setup.t is not a function
The test:
import { describe, test } from "vitest";
import { render } from "@testing-library/vue";
import { createI18n } from "vue-i18n";
import TheHeader from "@/components/TheHeader.vue";
const i18n = createI18n({
legacy: false,
locale: "en",
messages: { ... }
});
describe("TheHeader", () => {
test("Toggles the search input", async () => {
const wrapper = render(TheHeader, {
global: {
plugins: [i18n],
},
});
});
});
I've solved this problem in another test by this way:
const i18n = createI18n({
legacy: false,
locale: "en",
messages: {
en: {
error: "Error",
},
uk: {
error: "Помилка",
},
ru: {
error: "Ошибка",
},
},
});
const wrapper = render(
{
...TheError,
$setup() {
const { t } = useI18n();
return { t };
},
},
{
props: { message },
global: {
plugins: [i18n],
},
},
);
But It doesn't work in this case. I've seen same problem in stack overflow several times, but no answers , so I consider it as bug.
Component I try to test: https://github.com/Explicit12/utube/blob/main/src/components/TheHeader.vue
Activity