Write Frontend Unit Test
GitHub用于编写或更新Baserow前端单元测试,涵盖核心、高级及企业版代码。指导使用Vitest、Vue Test Utils等工具,遵循仓库现有模式,针对工具函数、Vuex存储和组件提供具体测试策略。
Trigger Scenarios
Install
npx skills add baserow/baserow --skill Write Frontend Unit Test -g -y
SKILL.md
Frontmatter
{
"name": "Write Frontend Unit Test",
"version": "1.0.0",
"description": "Write or update Baserow frontend unit tests for core, premium, or enterprise code using the repo's existing Vitest, Nuxt, Vue Test Utils, TestApp, and snapshot patterns."
}
Write Baserow Frontend Unit Tests
Use this skill when a task is to add, fix, or extend a frontend unit test in web-frontend, premium/web-frontend, or enterprise/web-frontend.
Do not invent a generic Vue testing style. This repo already has established patterns. Start by finding the closest existing spec and copy its setup shape.
First Step
Before editing, identify the test target:
- Pure utility or parser function
- Vuex store logic
- Vue component mounted with the shared app context
- Nuxt/Vue 3 component mounted directly with
mountSuspended - Premium or enterprise variant of one of the above
Then inspect the nearest existing spec in the same module area.
Useful searches:
Use rg as a faster equivalent when it is available.
find web-frontend/test premium/web-frontend/test enterprise/web-frontend/test -type f | grep '\.spec\.'grep -RInE "new TestApp\\(|new PremiumTestApp\\(|mountSuspended\\(" web-frontend/test premium/web-frontend/test enterprise/web-frontend/testgrep -RInE "toMatchSnapshot\\(|vi\\.fn\\(|vi\\.spyOn\\(" web-frontend/test premium/web-frontend/test enterprise/web-frontend/test
Tooling Used In This Repo
Current frontend unit tests use:
vitestfordescribe,test,expect,vi@vue/test-utils@nuxt/test-utils/runtimewithmountSuspended- Repo helpers such as
TestApp,PremiumTestApp,MockServer, and fixtures underweb-frontend/test - Snapshot assertions for rendered HTML when the component output matters
Important local files:
web-frontend/vitest.setup.tsweb-frontend/test/helpers/testApp.jspremium/web-frontend/test/helpers/premiumTestApp.js
vitest.setup.ts already mocks i18n, UUID generation, and WebSocket. Reuse that environment instead of re-mocking those globally in each spec.
Choose The Right Pattern
Pure utility tests
For functions in modules/*/utils/**, keep the test simple:
- Import the function directly.
- Use plain inputs and deterministic assertions.
- Prefer
toStrictEqual,toBe, or explicit formatted objects over snapshots.
Good examples:
web-frontend/test/unit/core/utils/date.spec.jsweb-frontend/test/unit/core/utils/string.spec.js
Store tests
For Vuex store behavior, prefer TestApp unless the existing spec clearly uses a temporary local store:
- Create
testApp = new TestApp()inbeforeEach. - Read
store = testApp.store. - Seed state through store actions or the mock server.
- Always
await testApp.afterEach()inafterEach.
Good examples:
web-frontend/test/unit/core/store/auth.spec.jsweb-frontend/test/unit/builder/store/dataSource.spec.js
If the code lives in premium and needs premium-only auth/license behavior, use PremiumTestApp.
Shared app component tests
For many components, especially older patterns or components coupled to store, router, registry, or client behavior:
- Create
testApp = new TestApp()ornew PremiumTestApp(). - Mount with
testApp.mount(Component, { props, propsData, slots, listeners, global }). - Prefer the existing helper in the file, for example
mountComponent(...). - Clean up with
await testApp.afterEach().
TestApp.mount supports both props and legacy propsData, and converts listeners into Vue 3 event props. Match the nearby spec instead of rewriting all setup.
Good examples:
web-frontend/test/unit/core/components/dropdown.spec.jspremium/web-frontend/test/unit/premium/view/calendar/calendarView.spec.js
Direct mountSuspended component tests
For newer Nuxt/Vue 3 component tests that do not need the full helper wrapper:
- Use
const testApp = useNuxtApp()inbeforeEachif the component expects injected app/store context. - Mount with
mountSuspended(Component, { props, slots, global: { provide, stubs, mocks } }). - Provide injected dependencies explicitly.
Good examples:
web-frontend/test/unit/builder/components/elements/components/HeadingElement.spec.js
Assertions
Prefer the narrowest assertion that proves behavior:
- Use
toStrictEqualortoEqualfor transformed data and store state. - Use
toBefor scalar values. - Use
vi.fn()andvi.spyOn()for event handlers and method calls. - Use snapshots for rendered markup where the repo already uses them.
Do not default to snapshots for pure logic.
When asserting reactive store objects, this repo sometimes normalizes them with:
JSON.parse(JSON.stringify(value))
Use that only when the nearby test does it for Vue reactivity serialization issues.
Don't assert internals, always assert visible result in the DOM. For instance don't use
expect(wrapper.vm.values.use_instance_smtp_settings).toBe(false) # BAD
Don't directly use vm properties.
Mocking And Fixtures
Prefer repo helpers over bespoke mocks:
- Use
testApp.mockServerwhen the behavior depends on store-backed API calls. - Use fixtures under
web-frontend/test/fixturesand premium or enterprise fixture folders when suitable. - Use
testApp.dontFailOnErrorResponses()only when the test intentionally exercises failing responses.
Do not build a large custom mock environment if TestApp already provides the needed app, client, registry, router, and store wiring.
File Placement
Follow the existing test tree:
- Core:
web-frontend/test/unit/... - Premium:
premium/web-frontend/test/unit/... - Enterprise:
enterprise/web-frontend/test/unit/...
Keep the spec near the feature area rather than creating a new generic test folder.
Validation
Run the narrowest relevant test command first.
Examples:
just f yarn test:core --run test/unit/core/components/dropdown.spec.jsjust f yarn test:core --run test/unit/core/store/auth.spec.jsjust f yarn test:premium --run ../premium/web-frontend/test/unit/premium/view/calendar/calendarView.spec.jsjust f yarn test:enterprise --run ../enterprise/web-frontend/test/unit/enterprise/plugins.spec.js
If a snapshot changes intentionally, review the diff instead of blindly accepting it.
Guardrails
- Do not introduce Jest APIs. Use Vitest APIs already present in the repo.
- Do not add a standalone mount helper when
TestApporPremiumTestAppalready fits. - Do not over-mock store, router, or client dependencies if the real test helpers can provide them.
- Do not mix unrelated styles in one file. Match the nearest local spec.
- Do not leave out
afterEachcleanup when usingTestApporPremiumTestApp. - Do not create broad integration-style tests when a focused unit test is enough.
Version History
- 2.3.3 Current 2026-08-20 09:13


