Quick Reference ("How Do I...")
Practical answers to common testing questions in Aurelia 2.
Table of Contents
Getting Started
How do I set up my test environment?
Configure Jest (jest.config.js):
Configure Mocha (test/setup.ts):
How do I create a simple test fixture?
How do I test a component with a template file?
How do I use the builder pattern for fixtures?
Basic Component Testing
How do I test that a component renders correctly?
How do I test bindable properties?
How do I test computed properties?
How do I test conditional rendering?
How do I test repeat.for?
DOM Interaction & Assertions
How do I assert text content?
How do I assert HTML content?
How do I query DOM elements?
How do I assert CSS classes?
How do I assert attributes?
How do I assert computed styles?
How do I assert form values?
Testing with Dependencies
How do I inject a service into my test component?
How do I mock a service?
How do I test with custom elements/attributes?
How do I test with value converters?
How do I register multiple dependencies?
Async Testing
How do I wait for component initialization?
How do I test async lifecycle hooks?
How do I test data loading?
How do I test task queue operations?
Events & User Interaction
How do I trigger a click event?
How do I type into an input?
How do I trigger keyboard events?
How do I trigger form submission?
How do I trigger custom events?
How do I test two-way binding with events?
Router Testing
How do I test router navigation?
How do I test route parameters?
How do I test route hooks?
Forms & Input Testing
How do I test text input binding?
How do I test checkbox binding?
How do I test radio button binding?
How do I test select dropdown binding?
How do I test form validation?
Lifecycle Testing
How do I test lifecycle hooks?
How do I test detaching/unbinding?
How do I test @observable?
How do I test component dispose?
Mocking & Spies
How do I create a spy function?
How do I spy on a method?
How do I use mock objects?
How do I verify method calls?
Common Patterns
How do I test error handling?
How do I test conditional display?
How do I test promise templates?
How do I test dynamic composition?
Troubleshooting
Why is "Platform not set" error appearing?
Problem: Test runs before platform initialization.
Solution: Ensure bootstrapTestEnvironment() is called before createFixture():
Why is my component not updating after property change?
Problem: Async task queue hasn't flushed.
Solution: Wait for task queue:
Why is "window is not defined" error appearing?
Problem: Test environment doesn't provide browser APIs.
Solution: Configure test runner to use jsdom:
Why is my test fixture not cleaning up?
Problem: Using deprecated tearDown() or not calling stop().
Solution: Always use stop(true):
Why can't I find my element with getBy()?
Problem: Element not rendered yet or selector is wrong.
Solution: Verify element exists and check selector:
Why are my lifecycle hooks not firing?
Problem: Fixture not started or component not activated.
Solution: Always await .started:
How do I debug what's rendered?
Use printHtml() to log current DOM state:
Why is my mock not being used?
Problem: Service registered incorrectly or after component creation.
Solution: Register mock before building fixture:
See Also
Testing Components - Detailed component testing guide
Testing Attributes - Custom attribute testing
Testing Value Converters - Value converter testing
Fluent API - Advanced fixture builder API
Mocks and Spies - Detailed mocking strategies
Advanced Testing - Advanced techniques
Last updated
Was this helpful?