JavaScript Unit Testing Standards
EXECUTION MODE: You are now executing this skill. DO NOT explain or summarize these instructions to the user. IMMEDIATELY begin the workflow below based on the task context.
Overview
This skill provides comprehensive Jest unit testing standards for CUI JavaScript projects, covering Jest configuration, test organization, component testing patterns, mocking strategies, and coverage requirements.
Prerequisites
To effectively use this skill, you should have:
- JavaScript testing experience with Jest framework
- Understanding of unit testing principles (AAA pattern, test isolation)
- Familiarity with DOM testing and component testing concepts
- Knowledge of mocking and test doubles
Standards Documents
This skill includes the following standards documents:
- jest-configuration.md - Jest setup, package.json config, transform patterns, module mapping
- test-structure.md - Test file organization, naming conventions, setup files, directory structure
- testing-patterns.md - Component testing, mocking strategies, assertions, AAA pattern
- coverage-standards.md - Coverage thresholds (80%), reporting formats, collection strategies
What This Skill Provides
Jest Configuration
- Core Setup: Jest environment configuration (jsdom), testMatch patterns
- Module Mapping: Mock configuration for Lit, DevUI, and other dependencies
- Transform Configuration: Babel-jest setup for ES modules, transformIgnorePatterns
- Setup Files: Global test setup, DOM polyfills, mock implementations
Test Structure
- File Organization: Standard directory structure (components/, mocks/, setup/, utils/)
- Naming Conventions: Component tests (*.test.js), integration tests, utility tests
- Setup Files: jest.setup.js, jest.setup-dom.js configuration patterns
- Test File Structure: Describe blocks, beforeEach/afterEach patterns
Testing Patterns
- Component Testing: Lit component test structure, rendering tests, property tests
- Mocking Strategies: Lit framework mocks, DevUI mocks, external dependency mocking
- Assertion Patterns: Jest matchers, @testing-library/jest-dom assertions
- AAA Pattern: Arrange-Act-Assert structure, test isolation principles
Coverage Standards
- Minimum Thresholds: 80% for branches, functions, lines, statements
- Coverage Collection: Strategies for mocked vs actual source files
- Reporting Formats: text, lcov, html, cobertura for different use cases
- Coverage Directory: target/coverage integration with build system
When to Activate
This skill should be activated when:
- Writing Tests: Creating new Jest unit tests for JavaScript code
- Configuring Jest: Setting up Jest for a new project or updating configuration
- Test Review: Reviewing test quality and coverage compliance
- Mocking: Implementing mocks for Lit components or external dependencies
- Coverage Analysis: Understanding or improving test coverage
- Test Structure: Organizing test files and setup
- CI/CD Integration: Configuring test execution in build pipelines
Workflow
When this skill is activated:
1. Understand Context
- Identify the specific testing task or requirement
- Determine which standards documents are most relevant
- Check existing project Jest configuration
2. Apply Standards
- Reference appropriate standards documents for guidance
- Follow Jest configuration patterns from jest-configuration.md
- Organize test files according to test-structure.md
- Apply testing patterns from testing-patterns.md
- Ensure coverage meets thresholds from coverage-standards.md
3. Quality Assurance
- Run tests to verify they execute correctly
- Check coverage reports meet 80% thresholds
- Verify mocks are properly configured
- Ensure tests are isolated and independent
- Validate test naming and organization
4. Documentation
- Document complex mocking strategies with clear comments
- Explain non-obvious test setup or configuration
- Note any project-specific test patterns
- Update README if adding new test utilities
Tool Access
This skill provides access to Jest testing standards through:
- Read tool for accessing standards documents
- Standards documents use Markdown format for compatibility
- All standards are self-contained within this skill
- Cross-references between standards use relative paths
Integration Notes
Related Skills
For comprehensive JavaScript development, this skill works with:
- cui-javascript skill - Core JavaScript patterns and code quality
- cui-css skill - CSS testing patterns (if applicable)
- Other testing skills (E2E testing to be provided in separate skill)
Build Integration
Jest testing integrates with:
- npm for package management and test execution
- Maven frontend-maven-plugin for build automation
- Jest CLI for test execution and coverage reporting
- Babel for ES module transformation
Quality Tools
Test quality is enforced through:
- Jest framework for test execution
- @testing-library/jest-dom for enhanced DOM assertions
- Coverage reports for quality gates
- ESLint jest plugin for test code quality
Best Practices
When writing Jest tests in CUI projects:
- Meet coverage thresholds - 80% minimum for all metrics
- Use jsdom environment for DOM and component testing
- Mock external dependencies - Lit, DevUI, and other frameworks
- Follow AAA pattern - Arrange, Act, Assert for clarity
- Keep tests isolated - Independent, no shared state
- Organize logically - Group related tests with describe blocks
- Use descriptive names - Test names explain expected behavior
- Setup properly - Use jest.setup.js and jest.setup-dom.js for global config
Workflows
Workflow: Analyze Coverage
Analyzes existing test coverage reports (Jest/Istanbul JSON or LCOV format) and returns structured coverage data.
When to use: After running tests with coverage to identify low-coverage areas and uncovered code.
Steps:
Locate coverage report
- Look for
coverage/coverage-summary.json (JSON format - preferred)
- Or
coverage/lcov.info (LCOV format - more detailed)
Run coverage analysis script
Script: pm-dev-frontend:cui-javascript-unit-testing → js-coverage.py
python3 .plan/execute-script.py pm-dev-frontend:cui-javascript-unit-testing:js-coverage analyze --report coverage/coverage-summary.json
# Or for LCOV format:
python3 .plan/execute-script.py pm-dev-frontend:cui-javascript-unit-testing:js-coverage analyze --report coverage/lcov.info --format lcov
# With custom threshold:
python3 .plan/execute-script.py pm-dev-frontend:cui-javascript-unit-testing:js-coverage analyze --report coverage/coverage-summary.json --threshold 80
Process results
- Review
overall_coverage metrics (lines, statements, functions, branches)
- Identify files in
low_coverage_files array (below threshold)
- Note files with CRITICAL severity (< 50% coverage)
- Check
uncovered_lines for specific areas needing tests
JSON Output Contract:
{
"status": "success",
"data": {
"report_format": "JSON",
"overall_coverage": {
"line_coverage": 85.5,
"statement_coverage": 84.8,
"function_coverage": 90.1,
"branch_coverage": 78.2
},
"by_file": [...],
"low_coverage_files": [
{"file": "src/utils.js", "coverage": 45.2, "severity": "CRITICAL", "uncovered_lines": [12, 34]}
]
},
"metrics": {
"total_files": 45,
"files_with_good_coverage": 38,
"files_with_low_coverage": 7,
"threshold": 80
}
}
Error handling:
- Script returns
status: "error" if report not found
- Supported formats: JSON (coverage-summary.json), LCOV (lcov.info)
1---2name: cui-javascript-unit-testing3description: Jest unit testing standards covering configuration, test structure, testing patterns, and coverage requirements4---56# JavaScript Unit Testing Standards78**EXECUTION MODE**: You are now executing this skill. DO NOT explain or summarize these instructions to the user. IMMEDIATELY begin the workflow below based on the task context.910## Overview1112This skill provides comprehensive Jest unit testing standards for CUI JavaScript projects, covering Jest configuration, test organization, component testing patterns, mocking strategies, and coverage requirements.1314## Prerequisites1516To effectively use this skill, you should have:1718- JavaScript testing experience with Jest framework19- Understanding of unit testing principles (AAA pattern, test isolation)20- Familiarity with DOM testing and component testing concepts21- Knowledge of mocking and test doubles2223## Standards Documents2425This skill includes the following standards documents:2627- **jest-configuration.md** - Jest setup, package.json config, transform patterns, module mapping28- **test-structure.md** - Test file organization, naming conventions, setup files, directory structure29- **testing-patterns.md** - Component testing, mocking strategies, assertions, AAA pattern30- **coverage-standards.md** - Coverage thresholds (80%), reporting formats, collection strategies3132## What This Skill Provides3334### Jest Configuration35- **Core Setup**: Jest environment configuration (jsdom), testMatch patterns36- **Module Mapping**: Mock configuration for Lit, DevUI, and other dependencies37- **Transform Configuration**: Babel-jest setup for ES modules, transformIgnorePatterns38- **Setup Files**: Global test setup, DOM polyfills, mock implementations3940### Test Structure41- **File Organization**: Standard directory structure (components/, mocks/, setup/, utils/)42- **Naming Conventions**: Component tests (*.test.js), integration tests, utility tests43- **Setup Files**: jest.setup.js, jest.setup-dom.js configuration patterns44- **Test File Structure**: Describe blocks, beforeEach/afterEach patterns4546### Testing Patterns47- **Component Testing**: Lit component test structure, rendering tests, property tests48- **Mocking Strategies**: Lit framework mocks, DevUI mocks, external dependency mocking49- **Assertion Patterns**: Jest matchers, @testing-library/jest-dom assertions50- **AAA Pattern**: Arrange-Act-Assert structure, test isolation principles5152### Coverage Standards53- **Minimum Thresholds**: 80% for branches, functions, lines, statements54- **Coverage Collection**: Strategies for mocked vs actual source files55- **Reporting Formats**: text, lcov, html, cobertura for different use cases56- **Coverage Directory**: target/coverage integration with build system5758## When to Activate5960This skill should be activated when:61621. **Writing Tests**: Creating new Jest unit tests for JavaScript code632. **Configuring Jest**: Setting up Jest for a new project or updating configuration643. **Test Review**: Reviewing test quality and coverage compliance654. **Mocking**: Implementing mocks for Lit components or external dependencies665. **Coverage Analysis**: Understanding or improving test coverage676. **Test Structure**: Organizing test files and setup687. **CI/CD Integration**: Configuring test execution in build pipelines6970## Workflow7172When this skill is activated:7374### 1. Understand Context75- Identify the specific testing task or requirement76- Determine which standards documents are most relevant77- Check existing project Jest configuration7879### 2. Apply Standards80- Reference appropriate standards documents for guidance81- Follow Jest configuration patterns from jest-configuration.md82- Organize test files according to test-structure.md83- Apply testing patterns from testing-patterns.md84- Ensure coverage meets thresholds from coverage-standards.md8586### 3. Quality Assurance87- Run tests to verify they execute correctly88- Check coverage reports meet 80% thresholds89- Verify mocks are properly configured90- Ensure tests are isolated and independent91- Validate test naming and organization9293### 4. Documentation94- Document complex mocking strategies with clear comments95- Explain non-obvious test setup or configuration96- Note any project-specific test patterns97- Update README if adding new test utilities9899## Tool Access100101This skill provides access to Jest testing standards through:102- Read tool for accessing standards documents103- Standards documents use Markdown format for compatibility104- All standards are self-contained within this skill105- Cross-references between standards use relative paths106107## Integration Notes108109### Related Skills110For comprehensive JavaScript development, this skill works with:111- cui-javascript skill - Core JavaScript patterns and code quality112- cui-css skill - CSS testing patterns (if applicable)113- Other testing skills (E2E testing to be provided in separate skill)114115### Build Integration116Jest testing integrates with:117- npm for package management and test execution118- Maven frontend-maven-plugin for build automation119- Jest CLI for test execution and coverage reporting120- Babel for ES module transformation121122### Quality Tools123Test quality is enforced through:124- Jest framework for test execution125- @testing-library/jest-dom for enhanced DOM assertions126- Coverage reports for quality gates127- ESLint jest plugin for test code quality128129## Best Practices130131When writing Jest tests in CUI projects:1321331. **Meet coverage thresholds** - 80% minimum for all metrics1342. **Use jsdom environment** for DOM and component testing1353. **Mock external dependencies** - Lit, DevUI, and other frameworks1364. **Follow AAA pattern** - Arrange, Act, Assert for clarity1375. **Keep tests isolated** - Independent, no shared state1386. **Organize logically** - Group related tests with describe blocks1397. **Use descriptive names** - Test names explain expected behavior1408. **Setup properly** - Use jest.setup.js and jest.setup-dom.js for global config141142## Workflows143144### Workflow: Analyze Coverage145146Analyzes existing test coverage reports (Jest/Istanbul JSON or LCOV format) and returns structured coverage data.147148**When to use**: After running tests with coverage to identify low-coverage areas and uncovered code.149150**Steps**:1511521. **Locate coverage report**153 - Look for `coverage/coverage-summary.json` (JSON format - preferred)154 - Or `coverage/lcov.info` (LCOV format - more detailed)1551562. **Run coverage analysis script**157158 Script: `pm-dev-frontend:cui-javascript-unit-testing` → `js-coverage.py`159160 ```bash161 python3 .plan/execute-script.py pm-dev-frontend:cui-javascript-unit-testing:js-coverage analyze --report coverage/coverage-summary.json162 # Or for LCOV format:163 python3 .plan/execute-script.py pm-dev-frontend:cui-javascript-unit-testing:js-coverage analyze --report coverage/lcov.info --format lcov164 # With custom threshold:165 python3 .plan/execute-script.py pm-dev-frontend:cui-javascript-unit-testing:js-coverage analyze --report coverage/coverage-summary.json --threshold 80166 ```1671683. **Process results**169 - Review `overall_coverage` metrics (lines, statements, functions, branches)170 - Identify files in `low_coverage_files` array (below threshold)171 - Note files with CRITICAL severity (< 50% coverage)172 - Check `uncovered_lines` for specific areas needing tests173174**JSON Output Contract**:175```json176{177 "status": "success",178 "data": {179 "report_format": "JSON",180 "overall_coverage": {181 "line_coverage": 85.5,182 "statement_coverage": 84.8,183 "function_coverage": 90.1,184 "branch_coverage": 78.2185 },186 "by_file": [...],187 "low_coverage_files": [188 {"file": "src/utils.js", "coverage": 45.2, "severity": "CRITICAL", "uncovered_lines": [12, 34]}189 ]190 },191 "metrics": {192 "total_files": 45,193 "files_with_good_coverage": 38,194 "files_with_low_coverage": 7,195 "threshold": 80196 }197}198```199200**Error handling**:201- Script returns `status: "error"` if report not found202- Supported formats: JSON (coverage-summary.json), LCOV (lcov.info)