mobxjs / mobx-angular

The MobX connector for Angular.
MIT License
483 stars 59 forks source link

Testing component injected with mobx store #77

Closed ekundayo-ab closed 6 years ago

ekundayo-ab commented 6 years ago

Hi, I appreciate the awesome work done to birth this package.

I have been trying to test an angular component which has a mobx store injected into it but I can't seem to get a way to mock the mobx store such that I can dynamically change the values returned by some methods in the store. with ng-redux I can do something like MockNgRedux.getSelectorStub(selectorComponent) to stub out the selector.

So i'll like to know if there is a way this can be done when testing a component which makes use of mobx-angular

adamkleingit commented 6 years ago

Hi, Thanks for the kind words :) This sounds like a general Angular question. A store is just a regular Injectable, so you can mock it anyway you'd like. I don't see how it's specific to MobX / mobx-angular.

So depending on which testing library you use, Jeft/Jasmine etc. - you can use stubs/spies to create a mock store, and configure it in Angular's TestBed: https://codecraft.tv/courses/angular/unit-testing/mocks-and-spies/ https://blog.danieleghidoli.it/2016/11/06/testing-angular-component-mock-services/

ekundayo-ab commented 5 years ago

Ok thanks @adamkleingit