JavaScript Unit Testing Standards
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
1---2name: cui-javascript-unit-testing3description: Jest unit testing standards covering configuration, test structure, testing patterns, and coverage requirements4---5
6# JavaScript Unit Testing Standards
7
8## Overview
9
10This skill provides comprehensive Jest unit testing standards for CUI JavaScript projects, covering Jest configuration, test organization, component testing patterns, mocking strategies, and coverage requirements.
11
12## Prerequisites
13
14To effectively use this skill, you should have:
15
16- JavaScript testing experience with Jest framework
17- Understanding of unit testing principles (AAA pattern, test isolation)
18- Familiarity with DOM testing and component testing concepts
19- Knowledge of mocking and test doubles
20
21## Standards Documents
22
23This skill includes the following standards documents:
24
25- **jest-configuration.md** - Jest setup, package.json config, transform patterns, module mapping
26- **test-structure.md** - Test file organization, naming conventions, setup files, directory structure
27- **testing-patterns.md** - Component testing, mocking strategies, assertions, AAA pattern
28- **coverage-standards.md** - Coverage thresholds (80%), reporting formats, collection strategies
29
30## What This Skill Provides
31
32### Jest Configuration
33- **Core Setup**: Jest environment configuration (jsdom), testMatch patterns
34- **Module Mapping**: Mock configuration for Lit, DevUI, and other dependencies
35- **Transform Configuration**: Babel-jest setup for ES modules, transformIgnorePatterns
36- **Setup Files**: Global test setup, DOM polyfills, mock implementations
37
38### Test Structure
39- **File Organization**: Standard directory structure (components/, mocks/, setup/, utils/)
40- **Naming Conventions**: Component tests (*.test.js), integration tests, utility tests
41- **Setup Files**: jest.setup.js, jest.setup-dom.js configuration patterns
42- **Test File Structure**: Describe blocks, beforeEach/afterEach patterns
43
44### Testing Patterns
45- **Component Testing**: Lit component test structure, rendering tests, property tests
46- **Mocking Strategies**: Lit framework mocks, DevUI mocks, external dependency mocking
47- **Assertion Patterns**: Jest matchers, @testing-library/jest-dom assertions
48- **AAA Pattern**: Arrange-Act-Assert structure, test isolation principles
49
50### Coverage Standards
51- **Minimum Thresholds**: 80% for branches, functions, lines, statements
52- **Coverage Collection**: Strategies for mocked vs actual source files
53- **Reporting Formats**: text, lcov, html, cobertura for different use cases
54- **Coverage Directory**: target/coverage integration with build system
55
56## When to Activate
57
58This skill should be activated when:
59
601. **Writing Tests**: Creating new Jest unit tests for JavaScript code
612. **Configuring Jest**: Setting up Jest for a new project or updating configuration
623. **Test Review**: Reviewing test quality and coverage compliance
634. **Mocking**: Implementing mocks for Lit components or external dependencies
645. **Coverage Analysis**: Understanding or improving test coverage
656. **Test Structure**: Organizing test files and setup
667. **CI/CD Integration**: Configuring test execution in build pipelines
67
68## Workflow
69
70When this skill is activated:
71
72### 1. Understand Context
73- Identify the specific testing task or requirement
74- Determine which standards documents are most relevant
75- Check existing project Jest configuration
76
77### 2. Apply Standards
78- Reference appropriate standards documents for guidance
79- Follow Jest configuration patterns from jest-configuration.md
80- Organize test files according to test-structure.md
81- Apply testing patterns from testing-patterns.md
82- Ensure coverage meets thresholds from coverage-standards.md
83
84### 3. Quality Assurance
85- Run tests to verify they execute correctly
86- Check coverage reports meet 80% thresholds
87- Verify mocks are properly configured
88- Ensure tests are isolated and independent
89- Validate test naming and organization
90
91### 4. Documentation
92- Document complex mocking strategies with clear comments
93- Explain non-obvious test setup or configuration
94- Note any project-specific test patterns
95- Update README if adding new test utilities
96
97## Tool Access
98
99This skill provides access to Jest testing standards through:
100- Read tool for accessing standards documents
101- Standards documents use Markdown format for compatibility
102- All standards are self-contained within this skill
103- Cross-references between standards use relative paths
104
105## Integration Notes
106
107### Related Skills
108For comprehensive JavaScript development, this skill works with:
109- cui-javascript skill - Core JavaScript patterns and code quality
110- cui-css skill - CSS testing patterns (if applicable)
111- Other testing skills (E2E testing to be provided in separate skill)
112
113### Build Integration
114Jest testing integrates with:
115- npm for package management and test execution
116- Maven frontend-maven-plugin for build automation
117- Jest CLI for test execution and coverage reporting
118- Babel for ES module transformation
119
120### Quality Tools
121Test quality is enforced through:
122- Jest framework for test execution
123- @testing-library/jest-dom for enhanced DOM assertions
124- Coverage reports for quality gates
125- ESLint jest plugin for test code quality
126
127## Best Practices
128
129When writing Jest tests in CUI projects:
130
1311. **Meet coverage thresholds** - 80% minimum for all metrics
1322. **Use jsdom environment** for DOM and component testing
1333. **Mock external dependencies** - Lit, DevUI, and other frameworks
1344. **Follow AAA pattern** - Arrange, Act, Assert for clarity
1355. **Keep tests isolated** - Independent, no shared state
1366. **Organize logically** - Group related tests with describe blocks
1377. **Use descriptive names** - Test names explain expected behavior
1388. **Setup properly** - Use jest.setup.js and jest.setup-dom.js for global config