Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Advanced Composables, Plugins & Architecture 16 mins read Free Lesson

Testing Vue 3 Components with Vitest & Vue Test Utils

Write fast, isolated unit tests, mock Pinia stores, and test emitted events and props.

Unit Testing Vue Components

import { mount } from '@vue/test-utils'
import { describe, it, expect } from 'vitest'
import CourseCard from './CourseCard.vue'

describe('CourseCard.vue', () => {
    it('renders free badge when is_free prop is true', () => {
        const wrapper = mount(CourseCard, {
            props: { title: 'Complete Vue 3', isFree: true }
        })
        expect(wrapper.text()).toContain('Free Access')
    })
})