Skip to content

Is there a way to obtain a standalone component mock while completely clearing out its imports array? #7193

Answered by satanTime
skorupka-k asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @skorupka-k,

The example you gave about MockBuilder and createComponentFactory is the way to go.

The issue with your request is that it would only work in case of @Input and @Output with FooStandaloneComponent, whereas, in reality, FooStandaloneComponent can have dependencies, provide services, expose view and content children etc which require correct imports and declarations even to produce a mock of it.

Could you elaborate your example to demonstrate the exact problem of having chains of MockBuilder?

If you need to keep SomeModule, you can also use ngMocks.globalKeep(SomeModule).
Then the code would be:

const createComponent = createComponentFactory({
  component: StandaloneComponen…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by satanTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants