mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-11 08:20:53 +00:00
## Summary Document that `vue-i18n` should not be mocked in tests — mount with a real `createI18n` plugin instance instead. ## Changes - **What**: Expanded `docs/testing/vitest-patterns.md` "Don't Mock `vue-i18n`" section with a concrete code example (covering both component and composable tests), guidance for asserting on translation keys with empty messages, and a real-example link to `src/components/searchbox/v2/__test__/testUtils.ts`. Added a callout at the top of `docs/testing/unit-testing.md` "Mocking Composables with Reactive State" cross-linking the new section, since that section applies to *owned* composables. ## Review Focus - The previous `vitest-patterns.md` paragraph pointed at a non-existent `SearchBox.test.ts`; the new link points to the actual shared `testI18n` helper. - The "Mocking Composables with Reactive State" pattern should not be applied to third-party composables like `useI18n` — the callout makes that explicit. Surfaced during review of #11737, where the test file mocked `vue-i18n` and then accumulated structural workarounds (hoisted aliases, helper functions, type casts) to interact with the mocked `t`. A real `createI18n` instance avoids the entire ceremony. ┆Issue is synchronized with this [Notion page](https://app.notion.com/p/PR-11776-docs-prefer-real-createI18n-over-mocking-vue-i18n-in-tests-3526d73d365081d4bc39fbf3c2502e49) by [Unito](https://www.unito.io) Co-authored-by: Amp <amp@ampcode.com>
ComfyUI Frontend Testing Guide
This guide provides an overview of testing approaches used in the ComfyUI Frontend codebase. These guides are meant to document any particularities or nuances of writing tests in this codebase, rather than being a comprehensive guide to testing in general. By reading these guides first, you may save yourself some time when encountering issues.
Testing Documentation
Documentation for unit tests is organized into three guides:
- Component Testing - How to test Vue components
- Unit Testing - How to test utility functions, composables, and other non-component code
- Store Testing - How to test Pinia stores specifically
Testing Structure
The ComfyUI Frontend project uses colocated tests - test files are placed alongside their source files:
- Component Tests: Located directly alongside their components (e.g.,
MyComponent.test.tsnext toMyComponent.vue) - Unit Tests: Located alongside their source files (e.g.,
myUtil.test.tsnext tomyUtil.ts) - Store Tests: Located in
src/stores/alongside their store files - Browser Tests: Located in the
browser_tests/directory (see dedicated README there)
Test File Naming
- Use
.test.tsextension for test files - Name tests after their source file:
sourceFile.test.ts
Test Frameworks and Libraries
Our tests use the following frameworks and libraries:
- Vitest - Test runner and assertion library
- @testing-library/vue - Preferred for user-centric component testing
- @testing-library/user-event - Realistic user interaction simulation
- @vue/test-utils - Vue component testing utilities (legacy; new tests must use @testing-library/vue)
- Pinia - For store testing
Getting Started
To run the tests locally:
# Run unit tests
pnpm test:unit
# Run a specific test file
pnpm test:unit -- src/path/to/file.test.ts
# Run unit tests in watch mode
pnpm test:unit -- --watch
Refer to the specific guides for more detailed information on each testing type.