Answer the question
In order to leave comments, you need to log in
How to test a component with a local MobX store?
There is a class component, in its constructor the local store MobX is initialized like this:
constructor(props) {
super(props);
this.store = new SubscribeStore({
userId: this.props.userId,
type: this.props.isFollowers ? 'followers' : 'subscriptions'
});
}
Answer the question
In order to leave comments, you need to log in
Here's a different concept for you when testing. Test the functionality of the component, not the strings and functions of the component. Moreover, it is a mistake to take out private functions in the global space.
Write your tests in such a way that they don't fail if you then rewrite your application, removing mobh from it and rewriting components to hooks, but leaving the former functionality of the component.
Even write unit tests for the user. The user doesn't care if you used a component with mobh or hooks and a context.
So far I have made such a decision, maybe it will be useful to someone. But I think it's a crutch.
1) I import my class under test
2) I extend from this class with a new one
3) In the constructor I assign another object with mocks to this.store
4) in componentDidMount I call super.render ()
All this is done by rendering shallow from enzyme, and ShallowRenderer from Jest
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question