Component unit tests development (Vue Test Utils)

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

Developing Unit Tests for Components (Vue Test Utils)

Vue Test Utils—official library for testing Vue 3 components. Works with Vitest (recommended) or Jest. Mounts component in isolated environment, lets you check rendering, events and reactivity.

Setup (Vue 3 + Vitest)

npm install -D @vue/test-utils vitest jsdom @vitejs/plugin-vue
// vitest.config.ts
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
    plugins: [vue()],
    test: {
        environment: 'jsdom',
        globals: true,
    },
});

Basic Mounting

import { mount, shallowMount } from '@vue/test-utils';
import UserCard from './UserCard.vue';

describe('UserCard', () => {
    it('renders user name', () => {
        const wrapper = mount(UserCard, {
            props: { user: { name: 'John Doe', email: '[email protected]' } },
        });

        expect(wrapper.text()).toContain('John Doe');
        expect(wrapper.find('[data-testid="email"]').text()).toBe('[email protected]');
    });

    it('emits delete event', async () => {
        const wrapper = mount(UserCard, {
            props: { user: { id: 42, name: 'John' } },
        });

        await wrapper.find('[data-testid="delete-btn"]').trigger('click');
        expect(wrapper.emitted('delete')).toBeTruthy();
        expect(wrapper.emitted('delete')![0]).toEqual([42]);
    });
});

Testing with Pinia Store

import { setActivePinia, createPinia } from 'pinia';
import { useCartStore } from '@/stores/cart';

describe('CartButton', () => {
    beforeEach(() => {
        setActivePinia(createPinia());
    });

    it('adds item to cart', async () => {
        const wrapper = mount(CartButton, {
            props: { productId: 1 },
            global: { plugins: [createPinia()] },
        });

        const store = useCartStore();
        expect(store.items).toHaveLength(0);

        await wrapper.find('button').trigger('click');
        expect(store.items).toHaveLength(1);
    });
});

Testing Async Components

it('loads and displays data', async () => {
    vi.mock('@/api', () => ({
        fetchUser: vi.fn().mockResolvedValue({ name: 'Maria' }),
    }));

    const wrapper = mount(UserProfile, { props: { userId: 1 } });

    // Wait for loading
    expect(wrapper.find('[data-testid="loading"]').exists()).toBe(true);

    await flushPromises(); // from '@vue/test-utils'

    expect(wrapper.find('[data-testid="loading"]').exists()).toBe(false);
    expect(wrapper.text()).toContain('Maria');
});

Testing Slots

it('renders default slot', () => {
    const wrapper = mount(Card, {
        slots: {
            default: '<p data-testid="slotted">Content</p>',
            header: 'Card Header',
        },
    });

    expect(wrapper.find('[data-testid="slotted"]').exists()).toBe(true);
    expect(wrapper.find('.card-header').text()).toBe('Card Header');
});

Stubs for Child Components

// shallowMount—automatically stubs child components
const wrapper = shallowMount(ParentComponent);
// Child components render as <child-component-stub>

// Explicit stubs
const wrapper = mount(ParentComponent, {
    global: {
        stubs: {
            BaseIcon: { template: '<span></span>' },
            RouterLink: { template: '<a><slot /></a>' },
        },
    },
});

Testing Composables

// composables/useForm.test.ts
import { useForm } from './useForm';

test('validates email field', () => {
    const { fields, validate } = useForm({
        email: { value: '', rules: ['required', 'email'] },
    });

    fields.email.value = 'not-an-email';
    const isValid = validate();

    expect(isValid).toBe(false);
    expect(fields.email.error).toBe('Enter valid email');
});

Timeline

Setup + write tests for 20–30 components of existing Vue project: 4–7 days.