[Feature] Component testing Vue plugins
See original GitHub issueIs there a way to run component tests for Vue Router? For example when sombody wants to test if a link is rendered correctly (see test below) or to test if the user can click on a link and is able to navigate to the correct page?
Related to issue: Plugin Mounting Options
import { test, expect } from '@playwright/experimental-ct-vue';
import ComponentWorksNot from './ComponentWorksNot.vue';
test('renders a link', async ({ mount }) => {
const component = await mount(ComponentWorksNot, {
props: {
test: 'test'
}
});
await expect(component).toHaveAttribute('href', '/'); // fails because RouterLink is not resolved
});
<script lang="ts" setup>
import { RouteName } from '../router';
const props = defineProps<{ test: string }>()
</script>
<template>
<RouterLink :to="{ name: RouteName.TEST }">{{ props.test }}</RouterLink>
</template>
Full repo can be viewed here
Issue Analytics
- State:
- Created a year ago
- Comments:12 (11 by maintainers)
Top Results From Across the Web
Plugins - Vue Test Utils
A Vue Test Utils plugin is simply a function that receives the mounted VueWrapper or DOMWrapper instance and can modify it. Basic Plugin...
Read more >A guide to Vitest automated testing with Vue components
Component testing catches issues relating to components' props, events, styles, classes, lifecycle hooks, and more.
Read more >Testing Vue Components With Cypress - CSS-Tricks
It also feels like component level tests are a powerful documentation tool. The tests should assert all the critical features of a component...
Read more >Write Your First Vue Component Test - Gleb Bahmutov
fast to write and run; effective at covering lots of code; can perform visual testing via 3rd-party plugins. You can write E2E tests...
Read more >How to test Vue.js plugins and extensions - Chris Hager
Vue.js internal feature tests - Contain a lot of interesting, high-quality tests of directives, components and everything else (eg.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for explaining! It seems to me that Vue is sensitive to this limitation rather than VTU. Would also be good to know what other people think about this issue.
I still believe that global plugin registration would be a huge benefit and will make playwright Vue usable in most cases. Is this something that can already be added? Maybe we can progress later on the “per test plugin registration/overrides”?
Edit:
@pavelfeldman Playwright React community has similar problems:
#15325 How can I use component testing with Redux components
#14750 Need a complex example to test react component which requires internationalization and redux store
#14707 Add feature to allow mocking useRouter in Next.js for component testing
#14345 Allow custom mount fixture for component testing
Exposing the app in ‘playwright/index.ts’ sounds like a good idea to me! However i think it’s stil useful to that users are able to override the globally defined plugin options per test. Creating separate files for each override would be a lot of work.
Maybe we can start with the global plugins? And see later how to override the plugin options per test?