Decision Trees
Table of Contents
1. What Should I Test?
START: I need to test...
│
├─ Component rendering?
│ │
│ ├─ Static content only?
│ │ └─→ Use assertText() / assertHtml()
│ │ Example: fixture.assertText('Hello World');
│ │
│ ├─ Dynamic content with bindings?
│ │ └─→ Test initial state + binding updates
│ │ Example: component.value = 'new'; assertText('new');
│ │
│ └─ Conditional rendering (if/show)?
│ └─→ Test both shown and hidden states
│ Example: component.show = false; assertHtml('');
│
├─ User interactions?
│ │
│ ├─ Form inputs?
│ │ └─→ See Decision Tree #7
│ │
│ ├─ Button clicks?
│ │ └─→ Use trigger.click()
│ │ Example: trigger.click('button');
│ │
│ └─ Keyboard events?
│ └─→ Use trigger.keydown() / trigger.keyup()
│ Example: trigger.keydown('input', { key: 'Enter' });
│
├─ Component lifecycle?
│ │
│ └─→ Track hook calls with flags
│ Example:
│ const calls = [];
│ class { binding() { calls.push('binding'); } }
│
├─ Data fetching / async operations?
│ │
│ └─→ See Decision Tree #5
│
├─ Component with dependencies?
│ │
│ └─→ See Decision Tree #3
│
├─ Routing behavior?
│ │
│ ├─ Navigation?
│ │ └─→ Test router.load() and currentRoute
│ │
│ ├─ Route parameters?
│ │ └─→ Test params passed to component
│ │
│ └─ Route hooks (canLoad, loading)?
│ └─→ Invoke hooks manually or test via navigation
│
├─ State management?
│ │
│ ├─ Local component state?
│ │ └─→ Test property changes and rendering
│ │
│ ├─ @observable properties?
│ │ └─→ Test propertyChanged() callbacks
│ │ Example:
│ │ component.count = 5;
│ │ expect(component.onCountChanged).toHaveBeenCalled();
│ │
│ └─ Store/global state?
│ └─→ Mock store and test state updates
│
└─ Error handling?
│
└─→ Test error state and recovery
Example:
await component.load(); // Triggers error
expect(component.error).toBeTruthy();2. Which Fixture Creation Method?
3. How Should I Mock Dependencies?
4. Which Assertion Method?
5. How to Test Async Behavior?
6. Which Lifecycle Hook to Test In?
7. How to Handle User Interactions?
8. Should I Write a Unit Test or Integration Test?
Summary
Last updated
Was this helpful?