-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
Angular 19: Unexpected "HostComponent" found in the "declarations" array of the "TestBed.configureTestingModule" call #682
Comments
I have the same issue with
adding this to imports did nothing
I now have a ton of broken tests after the Angular upgrade |
So there is a workaround that i got to work for Create a Dummy component and specify
Then for a pipe or override the Pipe example:
Directive example:
@ssougnez For your case this should work.
Basically the issue is this component here because it does not specify |
This is not a work around for the case of mocking standalone components which is what I need |
Thanks a lot for the investigation, but wouldn't it be more clean to have a new major version of the library only supporting ng 19 and taking into account standalone component? |
Sure you are right but this project doesn't look to active does it? So the last release isn't even in npm ans over 2 months ago so don't know when an update will come. So we will have a workaround for now to proceede with NG19 and if there is an major update fine if not we will move away from it. |
The workaround is just recreating the current behaviour of the HostComponent in the project but with a NG19 component. The componen you are testing is still standalone his is just the "host component" around your component that you set via |
Yeah, this is more my concern actually. As for you other answer, I guess it's a good workaround that I'll probably use waiting for a real solution to be implemented or for me to have time to replace this library. Thanks a lot :-) |
I'm working on a PR for this. The lead maintainer has been quite helpful in accepting and coaching PRs in the past - I wouldn't get down on the library, just contribute! This is what open-source dev tools are all about. |
@carflynn2009 - to mock a standalone component, this bugfix isn't needed. You can do it right now by using the import { MockComponent } from 'ng-mocks';
...
let spectator: Spectator<FooComponent>;
const createComponent = createComponentFactory( // Or whatever factory
{
component: FooComponent,
imports: [
MockComponent(InnerComponent)
]
}); |
Going back to my original post this is exactly what I was doing and it still gives the same error , I cannot mock standalone components since angular 19 |
@johncrim if you look at the code I have it does not work |
@carflynn2009 - I have tests with Did you try |
That is what I I thought that it should just work but as soon as I upgraded every test I have with mock fails , I will try ng clean |
@carflynn2009 did your issues disappear when upgrading to the latest spectator version. After the upgrade I still run into this
|
Is this a regression?
No
Description
I just updated a library to use Angular 19 and Spectator 19 and I'm having the following issue for all my tests:
Here is the test:
And the badge component in itself is not really complex. It's a simple component with the "standalone" flag set to "true". I don't think it's related to the component itself as I have tests for 30+ components and they all fail with the same error.
I tried by using the
imports
array but it did not change anything:I also try setting
declareComponent
to false with no luck.Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in
Anything else?
No response
Do you want to create a pull request?
No
The text was updated successfully, but these errors were encountered: