Skip to content

[Question] playwright-ct (Vue): using (global) plugins inside component tests #17704

@jeffhuys

Description

@jeffhuys

Hi! I'm trying to use the experimental component testing part of Playwright.
I saw this issue kind of asking the same thing: #15472
And that issue was marked completed, mentioning this PR: #15551

However, I don't see how that PR would work in my case. I am mounting a component that uses the global variable $t which is a function that translates every string for us.
In our main.ts, it looks a bit like this:

import { App, createApp } from 'vue';
import i18n from '@/translations/plugin';

const app = createApp(AppComponent);
// ... other plugins
app.use(i18n);
// ... other plugins
app.mount('#app');

And inside @/translations/plugin.ts, it looks like this:

import { useI18n } from '@/translations';
import { Plugin } from 'vue';

const plugin: Plugin = {
  install(app) {
    const { t, format } = useI18n();

    app.config.globalProperties.$t = t;
    app.config.globalProperties.$format = format;
  },
};

export default plugin;

This exposes the $t variable to our entire app, to use in the templates.

Is there any way to make this work inside the components as well? Am I reading the PR I mentioned correctly that it only allows beforeEach and afterEach?

Thanks for reading, and please let me know if you need more details!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions