Skip to content

Frontend testing

Frontend tests run on Vitest with @vue/test-utils in jsdom. They test a feature through its public surface: unit tests cover pure transformations, component integration tests mount the real feature and assert what the user or the parent sees. Before writing a spec, identify the component boundary (owned children, stores, composables, utils, REST services, GraphQL operations, portals, required plugins) and decide which action drives the behaviour and which DOM, emitted event, store state, URL, or history effect proves it. Older specs may predate these rules; do not copy them blindly.

Run tests

yarn test            # all specs, TZ=UTC
yarn test:watch      # watch mode
yarn test:coverage   # with coverage
yarn test bookmarks  # only spec files whose path matches

Configuration lives in vitest.config.mts: jsdom environment, root app/frontend/src, and the global setup file tests/shared/utils/vitestSetup.ts.

What Vitest covers

Vitest covers only code under app/frontend/src/ and the Vite entrypoints in app/frontend/entrypoints/. The location of the tested source decides, not the location of the spec: do not import, copy, or evaluate JavaScript from outside these trees in a spec, not even a vendored dependency such as jQuery.

  • Other JavaScript, such as plugin assets/javascripts/ and scripts rendered by Ruby helpers or views, gets end-to-end coverage only when a substantial change affects a core workflow (Playwright tests).
  • Specs for easy_legacy_js/ code are an exception with their own rules in app/frontend/src/easy_legacy_js/AGENTS.md.

Tests structure

Base test structure

app/frontend/src/tests/
├── tests/<feature>/  # Feature suites, e.g. rich_menu, translation_modal, easy_ai, design_system
├── shared/           # Cross-cutting helpers: utils/, mocks/, stubs/, fixtures/, types/

Put a helper in shared/ only when several features use it; keep feature-scoped assets inside the feature directory.

Module test structure

<feature>/
├── fixtures/  # Scenario data, entities, locales, API responses
├── types/     # Fixture types and selector enums (dataCy.ts)
├── tests/     # Specs (*.spec.ts), optionally split by submodule
├── mock/      # Optional local mocks (some features use mocks/)
├── utils/     # Optional local helpers

Choose the test level

Behaviour Test
Pure mapping, validation, formatting Unit test of the function, scenario matrix from fixtures
Feature behaviour in a component Real component integration test
Full browser flow across pages or the backend Playwright end-to-end test

Do not add new coverage targets or boilerplate specs for trivial changes.

Write a component integration test

Prepare fixtures and mocked responses, mount in beforeEach, interact from the outside, and assert the observable result. bookmarks is a made-up module: the example shows the pattern, not an existing spec.

import { beforeEach, describe, expect, it } from "vitest";
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
import { createPinia } from "pinia";

import BookmarkList from "@/src/bookmarks/components/BookmarkList.vue";
import apollo from "@/src/shared/plugins/apolloClient";
import { ApolloType, mockApollo } from "@/src/tests/shared/mocks/apollo";
import { mockEasyLocale } from "@/src/tests/shared/mocks/easyLocale";
import { getByDataCy } from "@/src/tests/shared/utils";
import { BOOKMARKS_QUERY_RESPONSE } from "@/src/tests/tests/bookmarks/fixtures/responses/bookmarksQueryResponse";
import { BookmarksDataCy, BookmarksSelector } from "@/src/tests/tests/bookmarks/types/dataCy";

describe("BookmarkList", () => {
  let wrapper: VueWrapper<InstanceType<typeof BookmarkList>>;

  const bookmarks = BOOKMARKS_QUERY_RESPONSE.data.bookmarks;

  beforeEach(async () => {
    mockEasyLocale({ loaded: true });
    mockApollo(apollo, ApolloType.query, { bookmarks: BOOKMARKS_QUERY_RESPONSE });

    wrapper = mount(BookmarkList, {
      props: { projectId: "42" },
      global: { plugins: [createPinia()] },
    });

    await flushPromises();
  });

  it("Renders one row per bookmark", () => {
    expect(wrapper.findAll(BookmarksSelector.Row)).toHaveLength(bookmarks.length);
  });

  it("Emits select with the bookmark id after clicking its row", async () => {
    await getByDataCy(wrapper, BookmarksDataCy.Row, bookmarks[0].id).trigger("click");

    expect(wrapper.emitted("select")).toEqual([[bookmarks[0].id]]);
  });
});

Name a wait that needs several steps, for example waitForDialogClose, so the spec says what it waits for. When several describes share the same options, wrap mount in a local helper such as mountBookmarkList.

Mount real components

  • Mount in the beforeEach of the describe that owns the scenario, after its fixtures and mocks are ready, or through a shared mount helper called there. Each test gets a fresh wrapper; nested describes reuse that setup instead of mounting again in individual tests, unless the case intentionally changes the component boundary.
  • Use mount, not shallowMount, with the plugins the tree needs (createPinia(), getTestingVuetify(), Antd).
  • Vuetify components are auto-imported like in production: install getTestingVuetify() when the component under test renders V* components, and do not pass components to it.
  • Keep owned child components, stores (Pinia), composables, and utility modules real. Do not mock them, do not replace owned children through global.stubs, and do not turn an integration test into a parent-only test with hand-written stubs.
  • Stubs are allowed only for irrelevant external UI or platform boundaries, preferably an existing one from tests/shared/stubs/. Keep them minimal and state the reason in the spec setup.
  • Use attachTo: document.body when the component renders portals, popovers, or dialogs.
  • When a rule is impractical for a case, document the exception in the spec setup or the merge request; do not silently weaken the test.

Prepare fixtures first

  • Put entities, locales, API payloads, and scenario data in files under the feature's fixtures/, typed in types/ when the data is reused, large, or drives a scenario matrix such as { description, props, expectations }. Trivial single-use values may stay inline.
  • Keep expectations explicit in the fixture or the assertion: classes, ARIA attributes, emitted payloads, text.
  • Loop scenario fixtures with it.each/describe.each. Gate cases that depend on environment, feature flags, or devices with it.runIf/it.skipIf, not with conditionals in the test body.
  • Never generate one describe/it per registry entry (icons, locales, enums); test a small sample and add a mount-free completeness check for the whole registry.
  • Do not embed application logic or branching flows in specs.

Mock only external boundaries

GraphQL. Do not vi.mock GraphQL API services. The global setup replaces the shared client @/src/shared/plugins/apolloClient with vi.fn() methods; register responses with mockApollo from @/src/tests/shared/mocks/apollo:

  • Call it in beforeEach before mounting, keyed by GraphQL operation name (bookmarks, createBookmark).
  • Each call replaces the previous implementation for its type, so register every query of a scenario in one call and every mutation in a separate ApolloType.mutation call.
  • An operation without a registered response resolves to undefined instead of rejecting, so the code under test fails later, typically when it reads data. Check the operation name first when a spec fails that way.
  • This also covers operations of mounted children; do not stub a child only to avoid its GraphQL operations.
  • Keep each response in its own fixture file named after the operation, such as bookmarksQueryResponse.ts or createBookmarkMutationResponse.ts.
  • The optional fourth argument delays the response by 10 ms on the fake timers; advance them before asserting.

REST. Mocking REST API services with vi.mock is allowed.

Existing factories. Reuse a mock factory the feature's test folder already has before writing a new one.

Select elements through data-cy

Name attributes name-of-module__name-of-element, kebab-cased and scoped to the owning module, with a --unique-id suffix when instances must be told apart (see Test attributes). Declare them per feature in types/dataCy.ts:

  • *DataCy enums hold raw data-cy values; query them with getByDataCy, getAllByDataCy, queryByDataCy, and queryAllByDataCy from @/src/tests/shared/utils. Pass the unique argument for suffixed values.
  • *Selector enums hold full CSS selectors, used only when a descendant, prefix, or non-data-cy selector is required.
  • Content teleported outside the wrapper, such as a DSDialog, is queried against document with queryByDataCy/queryAllByDataCy, or through getBodyWrapper() with the wrapper helpers.
  • Prefer existing helpers such as dispatchKeyboardEvent (tests/shared/utils/keyboard.ts) and clickOnBtnByDataCy.
export enum BookmarksDataCy {
  List = "bookmarks__list",
  Row = "bookmarks__row",
}

export enum BookmarksSelector {
  Row = `[data-cy^="${BookmarksDataCy.Row}--"]`,
}

getByDataCy(list, BookmarksDataCy.Row, bookmark.id);

Test from the outside

  • Change state through props (setProps), user interaction (trigger, setValue, .click(), keyboard helpers), and events. Use wrapper.vm only for exposed public methods.
  • Assert the DOM, emitted events, or store state, never private component internals. Use findComponent for child props only when they are part of the public contract.
  • Keep assertions on behaviour: visibility, text, classes, attributes, emitted payloads. Normalise HTML where markup differs only in formatting.
  • Start describe/it descriptions with a capital letter and keep them declarative ("Renders...", "Emits...").

Wait for asynchronous updates

  • await flushPromises() after mounting or an action that resolves mocked API calls; await nextTick() for a pending render.
  • await vi.dynamicImportSettled() when the component loads children through lazy imports.
  • Timers are fake for the whole run. Advance them with vi.advanceTimersByTime or vi.runAllTimersAsync for debounces, delays, and delayed mockApollo responses.

Rely on the global setup

tests/shared/utils/vitestSetup.ts runs before every spec file; do not redeclare what it provides:

  • Fake timers, initialised date libraries (en), and mocks of browser and platform globals (ResizeObserver, matchMedia, location, local storage, scrolling, <dialog>, window.EasyLocale, current user, settings, CKEditor, jQuery) and of the shared Apollo client.
  • After each test: cleared mocks and timers, an emptied document.body, and wrappers unmounted automatically (enableAutoUnmount).

Set up translations

The default locale mock returns "test translation" for every key. When an assertion checks a specific localized string, including substitution tokens, call mockEasyLocale({ locales, loaded: true }) from @/src/tests/shared/mocks/easyLocale in the suite beforeEach with a locale map from fixtures/.