Open cmcleese opened 1 year ago
The results are always the same. Error:
FAIL test/vitest/__tests__/MainComponent.test.ts > Main > renders the main component
TypeError: $setup.t is not a function
@cmcleese did you found a solution for this?
Edit: This seems to work for me, also for the vue-router composition api.
let router: Router
let i18n: I18n
beforeEach(async() => {
i18n = createI18n({
locale: 'en',
fallbackLocale: 'en',
legacy: false,
messages
})
router = createRouter({
history: createWebHistory(),
routes: routes
})
router.push('/')
await router.isReady()
})
describe('Testing login view', async () => {
it.only('should render', () => {
const wrapper = mount(LoginView, {
global: {
plugins: [i18n, router],
}
})
wrapper.isVisible()
})
})
Reporting a bug?
I have Vue 3 components that do not pass test and always fail with the error:
TypeError: $setup.t is not a function
Expected behavior
Defining the global plugin should work.
Even trying to manually mock
t
doesnt work:Reproduction
I am using Quasar for rapid scaffolding but should not matter. Clone repo: https://github.com/cmcleese/quasar-vuei18n-vitest
Simply run in cmd:
vitest
Test & component:
test/vitest/__tests__/NotifyComponent.test.ts
test/vitest/__tests__/demo/NotifyComponent.vue
System Info
Screenshot
No response
Additional context
No response
Validations