Helpful Properties, Functions, and Advanced Querying
Aurelia's testing utilities provide a rich set of properties and functions that go beyond basic component rendering. This section explores the advanced capabilities of the ComponentTester and auxiliary testing functions.
ComponentTester Properties
Core Properties
ComponentTester provides several key properties that help in component testing:
element
What it is: The root HTML element of the rendered component
Use cases:
Direct DOM manipulation checks
Accessing rendered component's root element
Verifying element attributes or classes
viewModel
What it is: The actual instance of the component's view-model
Key benefits:
Direct access to component's internal state
Ability to call methods and check properties
Simulate interactions programmatically
Lifecycle Control Methods
Lifecycle control methods allow precise management of component lifecycle:
manuallyHandleLifecycle()
Purpose: Take full control of component lifecycle methods
Key benefits:
Step-by-step lifecycle testing
Precise timing control
Simulate different lifecycle scenarios
Key Lifecycle Methods
bind()
: Manually trigger data bindingunbind()
: Manually remove data bindingsattached()
: Simulate component attachment to DOMdetached()
: Simulate component removal from DOM
Element Waiting Utilities
waitForElement
and waitForElements
waitForElement
and waitForElements
Waiting utilities help manage asynchronous rendering:
waitForElement
Waits for a single element to be present or absent
Configurable timeout and polling interval
Useful for testing async content loading
waitForElements
Waits for multiple elements
Similar configuration options to
waitForElement
Advanced Querying with waitFor
waitFor
Flexible Waiting Mechanism
waitFor
Most flexible waiting utility
Works with custom conditions
Supports complex querying scenarios
Last updated
Was this helpful?