-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Feature Request: Allow ng-mocks to work with standalone components #2687
Comments
FYI, before working on this issue we might want to see how this open issue in Angular will unwrap. |
Agree, makes sense. Is it a syntax sugar for a module with single export? @NgModule({
imports: [CoolModule, FooComponent, BarDirective, BazPipe],
declarations: [MyStandaloneComponent],
exports: [MyStandaloneComponent]
})
class StandaloneComponentModule {} Sorry, I haven't code with angular for a year already and missed this feature :) I'm asking, because it looks simpler to convert it like that in |
yeah, I think that's pretty much it. I believe it's not quite 1:1 comparison. There are some nuances, but for the purposes of unit testing I don't think these nuances are important. |
Hi, just to push this topic a little: I use ng-mocks a lot in conjunction with jests snapshot testing feature to reduce the bloat of rendered Angular Material Components as well as predictable false negatives in my test suite. Would love to use standalone components there, but i don't as the drawbacks in testing are to high for me at the moment. PS: tanks for this awesome lib, it helps a lot and speeds up things by quite a margin :) |
After some research: Anything imported in a standalone declaration cannot be used anywhere else. The exception is services. They are available in parent declarations. So if we mock a standalone declaration, it should simply provide provides from all imported modules. |
Hi @DmitryEfimenko, could I ask you test current implementation? Now it keeps the component and mocks its imports if the component is standalone. You can keep, exclude etc: // It does mock imports
MockBuilder(StandaloneComponent).keep(ImportedPipe); if you want to keep its imports too, then you need to add its config separately or use chain methods: // It doesn't mock imports
MockBuilder(StandaloneComponent).keep(StandaloneComponent, {shallow: false});
// It doesn't mock imports
MockBuilder().keep(StandaloneComponent); |
I don't quite have a playground for standalone components set up yet, but I'll get it going and give it a spin. Thanks! |
Ah, oki then. It should do the job :) I'm waiting for the update of |
Ah, also forgot. @Dominik-Kriese, if you have standalone things in your project, could you give a try to the latest updates: ng-mocks.zip? Thank you in advance! |
@satanTime I only had very small and dumb components as standalone components due to the risks of low test coverage, but those seem to work fine with the new updates provided by you :) |
Great. Thanks. Let's hope primeng will be released soon. |
you've mentioned |
It's a historical thing from the times when CI ran only 4 parallel jobs. To reduce the time for ensuring that e2e tests with 3rd-party libs work correctly, node_modules for the lib and e2e is shared and therefore depends on all 3rd-party libraries. Now, it's possible to add one more CI step to install node_modules separately for e2e tests. |
feat(core): Support of standalone declarations #2687
v14.0.0 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems. |
Describe the feature or problem you'd like to solve
Angular v14 is released and the standalone components are now available.
We need support for mocking of standalone component dependencies (anything that's inside of the
imports
property of the@Component
decorator).Proposed solution
It appears we should consider the standalone components affect existing APIs in the ng-mocks:
The following discussion will use
MyStandaloneComponent
as defined below:1. MockComponent
I think
MockComponent(MyStandaloneComponent)
should behave exactly like it used to - the component should be mocked. However, in addition, all the members of theimports
property should also be mocked2. MockBuilder
MockBuilder(MyStandaloneComponent)
should keep the implementation of theMyStandaloneComponent
itself. However, all the dependencies specified in theimports
property should be mocked.This would go well with the best practices of "shallow" component testing. If there's a need to "keep" one of the dependency of the
MyStandaloneComponent
, the developer can leverage the existing.keep(BarDirective)
functionality.Additional context
The text was updated successfully, but these errors were encountered: