statex icon indicating copy to clipboard operation
statex copied to clipboard

Unit test examples

Open Nxt3 opened this issue 7 years ago • 4 comments

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 avatar Jan 25 '18 21:01 Nxt3

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

Nxt3 avatar Feb 07 '18 20:02 Nxt3

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 avatar Feb 08 '18 19:02 rintoj

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

Nxt3 avatar Feb 08 '18 19:02 Nxt3

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.

rintoj avatar Feb 12 '18 19:02 rintoj