question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Component testing Vue plugins

See original GitHub issue

Is 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

ComponentWorksNot.test.ts:

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
});

ComponentWorksNot.vue:

<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:closed
  • Created a year ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sand4rtcommented, Jul 11, 2022

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

1reaction
sand4rtcommented, Jul 9, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found