Running Tests
Run All Tests
To execute the complete test suite:polkadot-dev-run-test with the following options:
--detectOpenHandles- Helps identify async operations that prevent Jest from exiting- Ignores test files in
node_modulesand files matching.*/ignore-.*\.(test|spec)\..*
Run a Specific Test
To run a single test file:Run Tests in Watch Mode
For test-driven development:Test File Structure
SubWallet follows these conventions for test files:File Naming
Test files use the.spec.ts extension:
Test Organization
Organize tests usingdescribe blocks and individual test or it statements:
Writing Tests
Basic Test Structure
Create a test file with the.spec.ts extension:
Testing Store Classes
When testing store classes that extendBaseStore or SubscribableStore:
Testing API Functions
For API functions that make external calls:Testing Message Handlers
For testing message handlers in the extension:Jest Configuration
The project uses a custom Jest configuration (jest.config.cjs) that extends @polkadot/dev configuration:
Module Name Mapping
The configuration maps package aliases for testing:Ignored Test Files
Tests matching these patterns are ignored:- Files in
node_modules - Files matching
.*/ignore-.*\.(test|spec)\..*
ignore-:
Mocking Browser APIs
SubWallet usessinon-chrome for mocking Chrome extension APIs:
Best Practices
Continuous Integration
Tests run automatically in CI/CD pipelines. Ensure all tests pass before:- Creating pull requests
- Merging to main branches
- Creating releases