-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When I use mocks, where do I leave them? #819
Comments
I usually add test specific content in a folder test-helpers under the root folder of the project. |
A mock implementation depends on what you want to test in your unit test. For me, it is a complete non-sense (and very dangerous) to factorize mock outside a unit test. Each component (service, directive, component, controller, filter) unit test file MUST have a specific self contained mock implementation for each dependency. For exemple if you have a unit test for a service named You MUST NOT implements service Notice that this is true in every language or context. It is not specific to angular or javascript. A unit test is by essence self sufficient. |
While @MarcLoupias's comment is very solid and generally sound advice, I do create a separate mock file whenever the service that I'm mocking is more generic, like your For your question about where to place such a mock file: I don't know what your folder structure looks like, but you could use separate strategies:
|
(This is about Angular 1)
So I have this beautiful service called
api.service.js
, and you might guess that this service is used in alot of tests. So I thought to create a mock for it, so it can be reused by many tests, but I'm not sure where to leave the mock in the folder structure. Does anyone have a suggestion?The text was updated successfully, but these errors were encountered: