Smart Spot for your Mocks In Your Frontend Typed App

Nasreddine Skandrani
Front-End Tricks — TheBlog
2 min readSep 12, 2018

I will go directly to the point. If you are writing tests. You need mocks for these tests. So the best spot to put your mocks is?

Let’s answer this question!

You understood from the image!! the mocks for the type JobStateare in a folderjob-state.mock near the file job-state.model.ts .

So if you have a type used in multiple modules, services or components of the app. Any developer in your team just have to ctrl-click the type to find the file of the type and near it look for a folder of mocks.

The developers will use the existing mocks from the folder and for new tests they will create new if needed. In case if the folder hasn’t been created yet they realize that they need to create the folder and the mocks.

Conclusion

This strategy is very useful for shared types especially. And with this strategy no one will never lose his mind searching for where the mocks for this type are…

Keep up with our content by following us @FrontEndTricks & don’t forget to give it some 👏👏👏.

~ Thank you ~

--

--