-
Notifications
You must be signed in to change notification settings - Fork 92
No automatic override for imports
on standalone components
#306
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
Comments
I'm in favor of adding a But I think this could get complicated if a child component also has its own imports that need to be mocked. We should keep that in mind, and try to find a solution for that as well. |
I've taken a first stab at this in #307 and got it working. Would love some feedback on the API. 🙏
For something more complicated like rendering with a template where you aren't passing in a specific component to override imports on, it might be possible to iterate through the list of specified imports and override a specific import on each standalone component. Something like: imports.forEach(token => {
if(isStandalone(token)) {
TestBed.overrideComponent(token, {add: {imports: [MockImportComponent]}, remove: {imports: [RealImportComponent})
}
}) Where you could pass in as an option some bindings of which classes to replace with with mocks. I honestly don't know how much of a value add that is. |
We can tackle it when it becomes a problem 😅. |
🎉 This issue has been resolved in version 12.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Problem
For standalone components, we define compiler scope like
When using angular testing library, define component compilation scope using the
declarations
andimports
property on therender
function.However, this does not overwrite the
imports
property of standalone components.Workaround
It is possible to manually override the
imports
property on a standalone component using TestBed.Proposed Solution
Perhaps we can use
TestBed.overrideComponent
to swap the imports already on a standalone component for theimports
array passed intorender
. Perhaps this can be guarded be a configuration flag likeoverrideComponentImports
.I might whip up a PR with this idea but just wanted to briefly discuss if this makes sense before putting in the work. Thanks!
The text was updated successfully, but these errors were encountered: