Test with Angular TestBed
In order to test components with Angular TestBed you need to do following:
prepare test environemt
strictActionCheck - since component template can have multiple components and we are not creating actions for each of them - we configure TestBed to not throw an error if actions for component were not found
createActions - creates actions for top component with initial state. All nested actions of nested components will be created automatically. tip: initialState, that top components was created with, should contain structure that matches nested component actions paths. For exmple: if your nested component actions path is @InjectStore([''${stateIndex}]) and your top component template is: <todo-description [statePath]="statePath" [stateIndex]="1"></todo-description> you need to make sure that initial state has array of todos with 2 items Also you can ovveride each action of nested components by creating custom ones by calling createActions. NgStateBed will look in list of custom actions before trying to create real ones.
and write your spec
tip: Since your components are using OnPush strategy please to rememeber:
To have your components extended with HasStore class
Have change detector ref injected into constructor with super call
call fixture.detectChanges each time you are interacting with UI or state
Last updated