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
Mocked component and host decorator #10
Comments
Here's an example I whipped up really quick: https://stackblitz.com/edit/bah?embed=1&file=app/hello.component.spec.ts The meat of it is:
|
I didn't know you could provide components, that's cool. But i modified your code to be closer to mine and it still didn't work.
It seems like it might be when projection is involved that the problem arises? Here is the modified one, i added a new spec file as well that is identical except is just removed MockComponent and those tests work. |
@kenborge looks like the issue here is related to the @ike18t showed that you can provide components in the TestBed.configureTestingModule({
declarations: [ HelloComponent ],
});
TestBed.overrideComponent(HelloComponent, {
set: {
viewProviders: [
{provide: AppComponent, useClass: MockComponent(AppComponent)}
]
}
}); I got that test running in this StackBlitz project, it's very similar to the one @ike18t provided, just using the different injection technique. |
@getsaf Creating a TestComponent does have some pretty valid use cases. Like if you want to test projected content. So you need to compile something like:
It does seem like this is possible with the viewProviders approach though. It doesn't work using normal provide like @ike18t mentioned, but overriding viewProviders seems to be a solution. |
@kenborge Did that solve your problem? Is it cool if I close this issue? |
Closing unless there is a reason not to. Feel free to reopen if this is still an issue. |
@ike18t yeah it did work using the viewProviders approach. I would still consider it a bug though or at least a limitation of the mock framework that maybe should be documented. |
If you have 2 nested components like this
And the inner component uses a host decorator to inject the outer component in it's constructor
constructor( @Host() public outer: OuterComponent ) { }
When you want to test the inner component it does not seem like it's possible to mock outer component in the tests as the component declared in the TestBed
MockComponent(OuterComponent)
is not found and injected into the constructor of the inner component.Is there any way to make this work?
The text was updated successfully, but these errors were encountered: