[Feature Request] Add Angular's overrideComponent properties to moduleMetadata #26274
Replies: 1 comment
-
This would be very nice to have and has been requested by others also. I don't think this would be simple to add, since we don't use the As for your proposed change to My initial thought for what would be expected is the following, but there may be a better solution: export default {
component: CancelButtonComponent,
title: 'CancelButton',
decorators: [
// This should more closely match the pattern users are familiar with, from the TestBed.
overrideComponent(CancelButtonComponent, {
remove: {
imports: [MatButtonModule],
},
add: {
imports: [MatButtonMock],
},
}),
],
} as Meta; One complication that I can think of is lazy loaded modules/components/directives/pipes, since we support multiple Angular applications running in the same document. Maybe this would be more clear, once an initial implementation is attempted or maybe someone more familiar with how overrides works could answer this. If StoryA applies overrides to MyComponent then I would think we have to clear the overrides before rendering StoryB, so StoryA rendering MyComponent after StoryB has rendered would not have the overrides. Hopefully I am just over thinking this, but that is one of my concerns for complication. |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
The problem I'm having with Angular Standalone Components: Unable to use mocked components or modules in Storybook moduleMetadata decorator. This could be for third party modules, or even first party standalone components which have other dependencies you'd want to avoid in testing or Storybook environments.
Example standalone component with a module I'd like to mock
The mock module I'd like to use
There is no way for me to use this mocked module in my Storybook configuration
// Unable
While in my test files I can use the Angular's testing tooling like so to replace the original module with the desired mock module:
Describe the solution you'd like
Something along the lines of the following:
Describe alternatives you've considered
No response
Are you able to assist to bring the feature to reality?
no
Additional context
Examples taken from this Medium article
Beta Was this translation helpful? Give feedback.
All reactions