.ai/principles/distilled/qa-jest.md
findByRole (DOM Testing Library) as the primary query method to enforce accessibility.findComponent(FooComponent) or find('input[name=foo]') or find('[data-testid="..."]') for unit tests.wrapper.find({ ref: 'foo' }) or .js-* class selectors for test queries.kebab-case for data-testid attribute values..js-* classes solely for testing purposes.${componentName}_spec.js.# or . prefix) as the describe block name when testing specific methods.async/await or by returning the Promise.done or done.fail callbacks when working with Promises.await nextTick() to wait for Vue re-renders.await waitForPromises() when Promises are triggered in synchronous lifecycle hooks.setTimeout or setImmediate for waiting in tests; use jest.runAllTimers, jest.runOnlyPendingTimers, or Promise-based helpers instead.jest.runAllTimers or jest.runOnlyPendingTimers instead of real timers; Jest uses fake timers by default.useFakeDate helper (not inline Date manipulation) to change the fake date within a describe block.useFakeDate or useRealDate inside it, beforeEach, or beforeAll blocks.useRealDate helper when real Date behavior is required.setWindowLocation helper to set window.location.href in tests.useMockLocationHelper when asserting that window.location methods were called.beforeEach; use afterEach to null out Apollo/store references.beforeDestroy/beforeUnmount).gon/window.gon directly in beforeEach for tests that depend on it; it resets automatically between tests.toBe (not toEqual) when comparing primitive values.toHaveLength, toBeUndefined, etc.) over generic ones for clearer error messages.toBeTruthy or toBeFalsy; use exact matchers instead.toBeDefined to assert element existence; use .exists()).toBe(true) instead.__mocks__/ next to source) for non-node_modules modules; place them in spec/frontend/__helpers__/mocks instead.jest.mock(..) in the relevant spec file instead.node_modules packages in spec/frontend/__mocks__.@client directive tests.{}, input variables object, expect.anything(), expect.anything().it.each / describe.each for parameterized tests to reduce repetition.jest.spyOn(Math, 'random').mockReturnValue(...) when the subject depends on Math.random.console.error or console.warn calls.ignoreConsoleMessages helper sparingly and only when absolutely necessary for test maintainability..exists(), .text(), element counts) over snapshots for element visibility, text presence, and complex HTML.spec/frontend/msw_integration/) by default for multi-component interaction on a single page.spec/features/) only when real backend state, navigation across server-rendered pages, or server-side validations are required.mount (not shallowMountExtended or mountExtended) in MSW integration tests.wrapper.find(), wrapper.trigger(), wrapper.text(), etc.).beforeEach and stop the client in afterEach to prevent state leakage.server.listen, server.resetHandlers, or server.close in individual MSW test files; these are handled globally by test_setup.js.handlers/ and register them in handlers.js.assignRouter from test_helpers.js to create a router; DO NOT call router factory functions directly or push routes manually.fullMount from test_helpers.js (wraps mount and attaches to document.body) to mount the root component with the real apolloProvider.afterEach cleanup for wrapper destruction or Apollo client teardown in MSW test files; test_setup.js handles this globally.loadFixturesMap from fixture_utils.js to auto-load fixtures from a directory and map them to operation names by camelCase conversion.OPERATION_NAME_OVERRIDES in the handler file.:js to specs or describe blocks that require JavaScript execution.wait_for_requests before asserting after navigation or asynchronous UI actions.project_pipeline_path) instead of hardcoded URL strings.before do block when testing the disabled state: stub_feature_flags(my_feature_flag: false).true; they are enabled by default in the test environment.expect_page_to_have_no_console_errors in an after block to assert no unexpected browser console errors.data-testid selectors over CSS class selectors; use .js-* or CSS class selectors only as a last resort.:aggregate_failures.test_fixtures alias.bin/rake frontend:fixtures or bin/rspec spec/frontend/fixtures/<file>.rb.spec/frontend/fixtures/ and EE fixture generators in ee/spec/frontend/fixtures/.ee/spec/frontend/fixtures/ and write JSON output to tmp/tests/frontend/fixtures-ee/graphql/.spec/frontend/__helpers__.testAction helper (object argument form) for testing Vuex actions.waitFor(url, callback) or waitForAll(callback) from the Axios mock helper when no direct Promise handle is available.shallowMountExtended or mountExtended to access DOM Testing Library queries (findByTestId, findByRole, etc.) on VTU wrappers.For the full picture, see: