appbuilder-testing
App Builder Testing
Generate and run Jest tests for Adobe App Builder actions and React Spectrum UI components. Scaffolds unit tests, integration tests, component tests, and mock helpers for Adobe SDKs.
Pattern Quick-Reference
Pick the template or reference that matches the user's intent. Default to assets/unit-test-template.js for generic test requests.
| User wants | Reference | Template / Asset |
|---|---|---|
| Unit test for an existing action | references/testing-patterns.md | assets/unit-test-template.js |
| Integration test against deployed action | references/testing-patterns.md | assets/integration-test-template.js |
| Component test for React Spectrum UI | references/component-testing-patterns.md | assets/component-test-template.js |
| Mock ExC Shell context in tests | references/component-testing-patterns.md | assets/shell-mock-helper.js |
| Mock AEM extension context in tests | references/component-testing-patterns.md | assets/uix-guest-mock-helper.js |
| Mock State SDK in tests | references/mock-catalog.md | assets/mock-state-sdk.js |
| Mock Files SDK in tests | references/mock-catalog.md | assets/mock-files-sdk.js |
| Mock Events SDK in tests | references/mock-catalog.md | assets/mock-events-sdk.js |
| Mock Database SDK in tests | references/mock-catalog.md | assets/mock-database-sdk.js |
| Full mock catalog (all SDKs) | references/mock-catalog.md | — |
| Contract test for API interactions | references/testing-patterns.md | — |
| Pre-deployment verification | references/checklist.md | — |
| Debug test failures | references/debugging.md | — |
Fast Path (for clear requests)
When the user's request maps unambiguously to a single pattern above — they name a specific test type, reference a template, or describe a use case that clearly matches one entry — skip straight to generation. Use the matched template and proceed directly.
Examples of fast-path triggers:
- "Write tests for my action" → Read the action source, use
assets/unit-test-template.js, generate immediately - "Help me mock State SDK" → Use
assets/mock-state-sdk.js, inject into test file - "Add integration tests" → Use
assets/integration-test-template.js, configure for deployed action - "Run tests with coverage" → Execute
npx jest --coverageoraio app test - "Test my component/page/form/table" → Read the component source, use
assets/component-test-template.js, wrap in Provider - "Mock shell context" → Use
assets/shell-mock-helper.js, inject into test file - "Test my AEM extension component" → Use
assets/uix-guest-mock-helper.js+assets/component-test-template.js
If there is any ambiguity — multiple test types needed, project structure unclear, or the user hasn't specified enough — fall through to the full workflow below.
Quick Reference
- Test directory: Place test files in
test/mirroring the action path, e.g.,test/actions/<action-name>/index.test.js. - Jest configuration: App Builder projects use Jest by default. Config lives in
package.jsonorjest.config.js. - Test command:
aio app test(wrapper) ornpx jest --coverage(direct). - Mock pattern: Use
jest.mock()at the top of test files to mock Adobe SDK dependencies before importing the action. - Response shape: All actions return
{ statusCode, body }— assert both in every test. - Error paths: Always test 200 (success), 400 (bad input), and 500 (SDK failure) scenarios.
- CommonJS: Action test files use
require()andmodule.exports(not ES imports). - Component test directory:
test/web-src/components/<ComponentName>.test.js(ortest/components/). - Provider wrapper: Always wrap in
<Provider theme={defaultTheme}>— Spectrum renders nothing without it. - ARIA selectors: Use
getByRole(), not CSS classes — seereferences/component-testing-patterns.mdselector table. - Async testing: Use
findBy*for data that appears async,queryBy*for absence,waitForfor state changes.
Full Workflow (for ambiguous or complex requests)
- Scan project structure — Check for existing
test/directory,jest.config.js, and test scripts inpackage.json. Scan bothsrc/for actions ANDweb-src/for UI components. - Identify targets to test — Parse
ext.config.yaml(orapp.config.yaml) for declared actions and their source paths. Checkweb-src/src/components/for React components. - Determine test types needed — Unit tests for logic, integration tests for deployed actions, contract tests for API interactions.
- **For each action:**a. Read the action source to identify SDK dependencies (State, Files, Events, Logger, etc.).b. Generate unit test using
assets/unit-test-template.jsas the base.c. Inject appropriate mocks fromreferences/mock-catalog.mdbased on detected dependencies.d. Add error scenario tests (missing params, auth failures, SDK errors). - **For each UI component:**a. Read the component source to identify dependencies (shell context, UIX guest, action calls).b. Generate component test using
assets/component-test-template.jsas the base.c. Wrap all renders in<Provider theme={defaultTheme}>— Spectrum renders nothing without it.d. Inject shell mock (assets/shell-mock-helper.js) or UIX guest mock (assets/uix-guest-mock-helper.js) as needed.e. Add loading, success, and error state tests for async data usingfindBy*andwaitFor. - Run tests — Execute
aio app testornpx jest --coverageand report results. - Validate — Check against
references/checklist.mdbefore marking done.
Example User Prompts
- "Write unit tests for my generic action"
- "Add integration tests for my deployed action"
- "My action uses State SDK — help me mock it in tests"
- "Run tests and show me coverage"
- "Set up Jest for my App Builder project"
- "Test my action handles errors properly"
- "Write component tests for my data table page"
- "Test my AEM extension panel component"
- "Help me mock shell context in my tests"
- "Add tests for my React Spectrum form"
Inputs To Request
- Current repository path and action file locations
- Which actions need tests (or test all declared actions)
- Target test types: unit, integration, contract, or all
- Whether action is deployed (needed for integration tests)
Deliverables
- Test files in
test/matching the action directory structure - Component test files in
test/web-src/components/for UI components - Mock helpers for detected Adobe SDK dependencies
- Shell or UIX Guest mock helpers when components depend on context SDKs
- Jest configuration if not already present (including jsdom environment for component tests)
- Coverage report from test execution
Quality Bar
- Every action test covers at minimum: success (200), bad input (400), and SDK failure (500) paths
- Mocks are isolated per test via
beforeEach(() => jest.clearAllMocks()) - No real SDK calls in unit tests — all external dependencies are mocked
- Tests are deterministic and can run offline (no network dependencies in unit tests)
- Coverage reporting is enabled (
--coverageflag) - All component tests wrap in
<Provider theme={defaultTheme}>— Spectrum renders nothing without it
References
- Use
references/testing-patterns.mdfor unit, integration, and contract test patterns with annotated examples. - Use
references/component-testing-patterns.mdfor React Spectrum component testing with Provider wrapping, ARIA selectors, and async patterns. - Use
references/mock-catalog.mdfor mock helpers covering all Adobe SDKs (State, Files, Events, Logger, Database, Shell, UIX Guest). - Use
references/checklist.mdfor pre-deployment test verification. - Use
assets/unit-test-template.jsfor Jest unit test boilerplate (CommonJS). - Use
assets/integration-test-template.jsfor integration test against deployed actions. - Use
assets/component-test-template.jsfor React Spectrum component test boilerplate withrenderWithSpectrum()helper. - Use
assets/shell-mock-helper.jsfor ExC Shell context mock (@adobe/exc-app). - Use
assets/uix-guest-mock-helper.jsfor AEM UIX Guest mock (@adobe/uix-guest). - Use
assets/mock-state-sdk.js,assets/mock-files-sdk.js,assets/mock-events-sdk.js, andassets/mock-database-sdk.jsfor ready-to-use SDK mock setups.
Common Issues
- Tests fail with "Cannot find module": Ensure the action path in
require()matches the actual file location. App Builder actions are typically atsrc/dx-excshell-1/actions/<name>/index.js. - Mocks not working:
jest.mock()calls must appear beforerequire()of the module under test. Jest hoists mock declarations but order still matters for manual mocks. - State/Files SDK tests fail: These SDKs require Runtime environment for real calls. Always mock them in unit tests. Use
aio app run(notaio app dev) for integration tests that need real SDK access. - Coverage too low: Add tests for error branches — missing params, invalid auth headers, SDK
init()failures, and timeout scenarios. aio app test** vsnpx jest:**aio app testis a thin wrapper around Jest. Usenpx jest --coveragedirectly for more control over flags and reporters.- Spectrum components render blank in tests: Missing
<Provider theme={defaultTheme}>wrapper. UserenderWithSpectrum()helper fromassets/component-test-template.js. - ARIA role queries return null: Spectrum components use ARIA roles, not CSS classes. See
references/component-testing-patterns.mdsection g for the role reference table.
Chaining
- Chains FROM
appbuilder-action-scaffolder(test actions after implementation) - Chains FROM
appbuilder-ui-scaffolder(test UI components after scaffolding) - Chains TO
appbuilder-cicd-pipeline(automated test execution in CI)
More from adobe/skills
scrape-webpage
Scrape webpage content, extract metadata, download images, and prepare for import/migration to AEM Edge Delivery Services. Returns analysis JSON with paths, metadata, cleaned HTML, and local images.
217create-component
|
202ensure-agents-md
|
198dispatcher
|
197aem-workflow
|
192code-review
Review code for AEM Edge Delivery Services projects. Use at the end of development (before PR) for self-review, or to review pull requests. Validates code quality, performance, accessibility, and adherence to EDS best practices.
186