statex
statex copied to clipboard
Unit test examples
Would it be possible to see todo-ng-ts with some unit testing? I'd be interested to see how statex can improve unit testing.
@rintoj Is there any way we could get a basic example on how to perform testing the state with Angular + Karma/Jasmine? Without such documentation or examples, my team is probably going to have to use another library. Testing is important.
Here is an example to show how to test StateX store. Hope this helps.
https://github.com/rintoj/statex/blob/master/examples/todo-ng-ts/src/store/todo-store.spec.ts
@rintoj What about testing a component with a store (i.e. testing values in the store are set after certain functions are called)? Or am I thinking about that incorrectly?
Hi @Nxt3, sorry for the delay.
StateX is configured for detached store and view. Therefore when you unit test a view, you must only test for appropriate actions being dispatched. What happens when an action is trigged must be tested under store's test case, not here.
This example should help you understand how to test that.
https://github.com/rintoj/statex/blob/master/examples/todo-ng-ts/src/app/list/list.component.spec.ts
And if you would like to test state mapping to the component State.next() can be used.