Decision Trees

Visual decision trees to help you choose the right testing approach for your scenario.

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

These decision trees should help you:

  1. Choose what to test based on your requirements

  2. Select the right fixture creation method for your scenario

  3. Mock dependencies appropriately based on complexity

  4. Use the correct assertion method for your verification

  5. Handle async behavior correctly

  6. Test in the right lifecycle hook for your needs

  7. Simulate user interactions accurately

  8. Decide between unit and integration tests

For more detailed information, see:

Last updated

Was this helpful?