-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Feature Request: allow to mock only specific methods #4367
Comments
Hi @serhiistotskyi, thank you for the request. I've fixed the part with Regarding partial mocks, it's bad practice and isn't supported by |
feat(MockInstance): ignores undefined properties #4367
v14.5.0 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems. |
Why is it a bad practice? I’ll look into our use cases and will let you know. But I had issues with Router and routerLink when I tried to completely mock router -> routerLink directive threw an error |
Basically, in unit tests you have a subject under test and the subject should stay as it is, and its dependencies should be mocked. If you have integration tests, then you have 2+ subjects under test and it's the same story - their dependencies should be mocked, but the subjects should stay as they are. Regarding the error when you mock, I think, it's because not all dependencies have been mocked, especially |
Describe the feature or problem you'd like to solve
Sometimes I want to mock just one method and leave the rest of the service as is. So, it can run some domain specific logic (or side-effects)
Proposed solution
Provide a function that has the same declaration as
MockProvider
but modifies service instead of creating a full mock:Additionally would be nice to ignore
undefined
values in object, i.e., if property isundefined
just ignore it and do not override service method/property:this allows to simplify pattern of using
setup
function and passing props inside:We use this pattern a lot in our codebase, together with
MockProvider
, so would be nice to have this built-in.Additional context
We have implemented this custom function using
APP_INITIALIZER
token:The text was updated successfully, but these errors were encountered: