rintoj / statex

StateX is a state management library for modern web applications with unidirectional data flow and immutable uni-state (just like redux)
MIT License
68 stars 18 forks source link

Unit test examples #11

Open Nxt3 opened 6 years ago

Nxt3 commented 6 years ago

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.

Nxt3 commented 6 years ago

@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.

rintoj commented 6 years ago

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

Nxt3 commented 6 years ago

@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?

rintoj commented 6 years ago

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.