-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
ngMocks.globalReplace doesn't seem to replace in standalone component #3161
Comments
Hi @DW8Reaper, thanks for the report. I'll take a look where the problem is. |
Thanks @satanTime I don't know if this helps or further confuses the issue but I have found anther funky thing might be related/causing this. If we have code like this: mockBuilder(SomeComponent, SomeModule)
.mock(SomeService, aCustomMockObjectWeMake) but the module SomeModule does not define or export SomeService (in fact no module in the test exports it). Previously it seems when we call .mock(SomeService, aCustomMockObjectWeMake) it would also automatically define a provider for that service if it didn't exist. I can fix it by doing this which I didn't need in ngMocks v13.0.3 mockBuilder(SomeComponent, SomeModule)
.mock(SomeService, aCustomMockObjectWeMake, {export: true}) So possibly there is a change to how that mock method works with services that aren't directly imported in any module in the test. I don't know if this is possibly related or causing the standalone component issue as well. I realize that maybe we should not be using ngMocks.mock with a service that isn't registered in any modules |
…encies help-me-mom#3161 MockBuilder will process dependencies of standalone declarations with respect of the next configuration: - ngMocks.globalKeep - ngMocks.globalMock - ngMocks.globalReplace - ngMocks.globalExclude
fix(MockBuilder): respects global configuration for standalone dependencies #3161
Hi @DW8Reaper, I hope this finds you well. the fix is here. Regarding Basically, you need to add MockBuilder(SomeComponent, [SomeModule, SomeService]).mock(SomeService, aCustomMockObjectWeMake); Then, it's clear that it's an external dependency and neither |
v14.1.1 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. |
Thanks @satanTime I missed that breaking change from 13 to 14 so that's my bad on that one, thanks for fixing the global mocks that looks like the change you made in v14.1.1. I'll give it a shot and update our mocks based on the required migrations and see how it works |
Sounds good! Thanks in advance! |
Description
I apologize that I don't have an easy reproduction added here but the basic issue is the following, when using standalone components (testing with NgMocks v14.1.0) any ngMocks.globalReplace calls don't seem to apply to those components.
So in our codebase we do a global setup that calls something like this:
Then in our code we have a standalone component:
and the test setup for the standalone component
However the test don't work because when the tests run it uses vanilla/automatic module mocks for the TranslateModule instead of using my global replacement.
Workaround
I can work around it by adding a replace directly in the test like this then it works again:
The text was updated successfully, but these errors were encountered: