Title is misleading and can hinder inexperienced users from following this nice coding convention.
This totally depends on the situation. Just an example in React where most of the time you will write components, "export default class" is and always the most accurate and concise behavior because:
You never rename the class, and you should always have 1 class in a file. That's also how you do should consider doing in OOP by the way.
If there is a sub class, put it in a separate files
For backend, where you can export a lot of APIs from a file, it is better if you put exported components in an object, just like how you do it with module.exports.
If you use redux, you should not export the class but “export default” the wrapper instead. There is no reason why sometimes you only want to export the class, but sometimes you export it wrapped in a Redux wrapper
But do you really want the class without Redux? In the end, redux is also a part of the logic a container has that needs to be tested.
I mean even in a test.js file, you will still want to test functionality that redux props bring? I don’t think it is a good idea to separate the logic of redux from the presentational component. But if you really need to test the presentational ones, you can directly import the class as we should isolate the container, which is wrapped by a connector, and the presentational component,
Yes, you really want the class without redux, you test redux separately. In fact, you test the action creators, the selectors, and the reducers, all separately.
You are talking about more of an integration test, or even higher level than that.
And why go through all that trouble of stubbing out what you need to just to get the component underneath, when you can just import it by name...
No extra downsides...
And, if you want to import the fully connected component for testing too, you can do that as well!
3
u/allicanseenow Aug 27 '18
Title is misleading and can hinder inexperienced users from following this nice coding convention.
This totally depends on the situation. Just an example in React where most of the time you will write components, "export default class" is and always the most accurate and concise behavior because:
You never rename the class, and you should always have 1 class in a file. That's also how you do should consider doing in OOP by the way.
If there is a sub class, put it in a separate files
For backend, where you can export a lot of APIs from a file, it is better if you put exported components in an object, just like how you do it with module.exports.