Test Structure
Tests are organized inlib/__tests__/ with the naming pattern *.test.ts.
Basic Test Template
Testing Utilities
Standards Compliance Tests
Test normalization functions for Indian GST standards:lib/__tests__/standards.test.ts:10-21
String Input Handling
Test parsing of various string formats:lib/__tests__/standards.test.ts:59-85
Edge Case Testing
Always test null, undefined, and boundary values:lib/__tests__/standards.test.ts:121-148
Testing Business Logic
Helper Function Tests
Test internal utilities using exported test helpers:lib/__tests__/invoice_v4.test.ts:1-67
Test Fixtures
Create reusable test data builders:lib/__tests__/invoice_v4.test.ts:147-211
Integration Tests
Test complete workflows with realistic scenarios:lib/__tests__/invoice_v4.test.ts:667-688
Testing Calculations
Discount Cascading
Test complex discount logic:lib/__tests__/invoice_v4.test.ts:271-289
GST Splitting
Test intra-state vs inter-state tax logic:lib/__tests__/invoice_v4.test.ts:391-434
Best Practices
Descriptive Test Names
Test names should describe behavior, not implementation:Arrange-Act-Assert Pattern
Structure tests clearly:Floating Point Comparisons
UsetoBeCloseTo for decimal precision:
lib/__tests__/invoice_v4.test.ts:116
Group Related Tests
Use nesteddescribe blocks for organization:
Testing Checklist
When writing tests, ensure you cover:- Happy path (typical valid inputs)
- Edge cases (null, undefined, empty, zero)
- Boundary values (min, max, near limits)
- Invalid inputs (wrong types, malformed data)
- Error conditions (exceptions, failures)
- Real-world scenarios (from actual invoices)
Related
- Testing Overview - Strategy and setup
- Running Tests - Commands and workflows
