-
Notifications
You must be signed in to change notification settings - Fork 93
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
feat: support componentImports option for standalone components #307
feat: support componentImports option for standalone components #307
Conversation
* A collection of imports to override a standalone component's imports with. | ||
* | ||
* @default | ||
* undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with the other default properties, I usually use an empty array.
* undefined | |
* [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I responded to this comment below.
@@ -55,6 +55,7 @@ export async function render<SutType, WrapperType = SutType>( | |||
wrapper = WrapperComponent as Type<WrapperType>, | |||
componentProperties = {}, | |||
componentProviders = [], | |||
componentImports, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
componentImports, | |
componentImports = [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rationale for leaving this undefined
by default is so we can optionally overwrite the imports when needed instead of overwriting them all the time. For a simple presentational component you might not need to mock any dependencies.
* ] | ||
* }) | ||
*/ | ||
componentImports?: (Type<any> | any[])[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this could change in the future, and I would like to be able to just do that without justifications 😅
Maybe we should mark it as experimental as well in the TS Docs?
componentImports?: (Type<any> | any[])[]; | |
ɵcomponentImports?: (Type<any> | any[])[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure np I can do that. Makes sense. I think the docs for standalone
and imports
mark them as experimental.
57c77e2
to
d8d009d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
🎉 This PR is included in version 12.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #306
This is a first stab at adding the ability to override the
imports
metadata field for standalone components.This PR adds the
componentImports
field to therender
function options. These imports are used to override the existing imports on a standalone component. The reasons for completely overriding imports are:TestBed.configureTestModule
.As implemented, this only works for the
render(FooComponent)
style rendering and throws an error ifcomponentImports
option is passed when the subject-under-test is template or non-standalone component.