-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
fix: unable to bind ngIf in angular 17+ #9314
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #9314 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 227 227
Lines 4935 4946 +11
Branches 1147 1148 +1
=========================================
+ Hits 4935 4946 +11 ☔ View full report in Codecov by Sentry. |
@satanTime Is there anything I need to change in this PR to help it get in & released ? (other than rebasing of course) This issue is currently preventing use of |
Hi @sabrina-10kc, Thank you for your contribution. |
Any update on this PR, @satanTime ? It would be really helpful to have this fixed. |
It would be great to get this merged. This can cause otherwise good tests to fail depending on when the error is thrown. |
Hi @sabrina-10kc, Thank you for this PR. I've tested it locally and it fix the problem in my projet. @satanTime Can you tell us if you have the time to merge this PR and release it, please ? |
Hello @satanTime when can you approve this? |
I wish it was so easy. |
@satanTime after reading this comment, please re-consider moving the version to the approach of angular and the current approach that the library has. It is a problem for people who want to use it to have to wait for months for something to be fix, because you need to be sure it works on all versions. The angular team just gave a speech a few days ago saying that they realize by time. Me and others want to contribute, but the current approach means everything will always fall on you. Yesterday, I installed the lib on a new machine to contribute with the specs and it took over 1h. The approach to develop the lib already takes 6GB in docker to be run, this is not a normal amount of space for a library that like you say, is just a wrapper for making life easier. Will this keep going until the machine reaches it's limit? People want to help, but it seems you don't want to be help, you don't really want others to collaborate with you. What would it take to help? I'm working on the schematics, but if there is anything I can help, tell. |
Not sure I understand your point. Old syntax is support in all angular versions it wasn't removed from a17 or a18. So I'm not sure how release change can improve that. Still both syntax should be supported for a18 and a17. |
My main issue is that this PR has been opened for a long time without any feedback from anybody. Really seems like you don't have the time to support the lib alone, but don't allow much help. |
Feel free to help, a test which would cover both beaches instead of ignoring one would help. |
Ok, will try to get it done between today and tomorrow. |
Great. Thanks. Is that branch cannot be covered at all - that’s also fine. I just need to be sure that that’s exactly like that. |
@satanTime I reviewed this with the focus on reaching the other part of the branch. When I did this, I got the following results: Angular 17+ branch:
Angular 16 and below:
From what I can tell, I'm worried that if this PR is merged, and a new version is released, in an Angular 16 or below app, it will break it. I may try to make a build and tested this myself with an actual use case, but would like your input on this before proceeding. Note: other that using this testing logic, I don't think there is a way to reach the other branch statement. In example you can find the spec file I used: import {
Component,
ContentChild,
NgModule,
TemplateRef,
VERSION,
} from '@angular/core';
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';
// @see https://github.com/help-me-mom/ng-mocks/issues/8884
describe('issue-8884', () => {
ngMocks.throwOnConsole();
describe('with a16 and below (added by me)', () => {
if (Number.parseInt(VERSION.major, 10) > 16) {
it('needs a16 or below', () => {
expect(true).toBeTruthy();
});
return;
}
@Component({
selector: 'app-target',
template: `<ng-template [ngTemplateOutlet]="content" />`,
})
class TargetComponent {
@ContentChild('content', {} as never)
content?: TemplateRef<any>;
}
@NgModule({
declarations: [TargetComponent],
})
class TargetModule {}
beforeEach(() => MockBuilder(null, TargetModule));
it('should create', () => {
MockRender(`<app-target>Test content</app-target>`);
expect(ngMocks.findInstance(TargetComponent)).toBeTruthy();
});
});
describe('with a17+', () => {
if (Number.parseInt(VERSION.major, 10) < 17) {
it('needs a17+', () => {
expect(true).toBeTruthy();
});
return;
}
describe('when standalone component does not import NgIf', () => {
@Component({
selector: 'app-standalone',
standalone: true,
template: `<ng-template [ngTemplateOutlet]="content" />`,
})
class StandaloneComponent {
@ContentChild('content', {} as never)
content?: TemplateRef<any>;
}
beforeEach(() => MockBuilder(null, StandaloneComponent));
it('should create', () => {
MockRender(`<app-standalone>Test content</app-standalone>`);
expect(ngMocks.findInstance(StandaloneComponent)).toBeTruthy();
});
});
describe('when NgIf is not available to a component in a module', () => {
@Component({
selector: 'app-target',
template: `<ng-template [ngTemplateOutlet]="content" />`,
})
class TargetComponent {
@ContentChild('content', {} as never)
content?: TemplateRef<any>;
}
@NgModule({
declarations: [TargetComponent],
})
class TargetModule {}
beforeEach(() => MockBuilder(null, TargetModule));
it('should create', () => {
MockRender(`<app-target>Test content</app-target>`);
expect(ngMocks.findInstance(TargetComponent)).toBeTruthy();
});
});
});
}); |
Use new angular control flow to avoid missing directive while mocking child templates Solves help-me-mom#8884
v14.13.1 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. |
When component templates contain child templates, they are replaced with a mock template that contains a
*ngIf
this causes a failure when the component doesn't have NgIf imported.Though this problem likely exists in some pre-angular 17 situations, it has been causing new failures to appear as people upgrade since 3rd party angular components are starting to use the new control flow syntax and no longer import
CommonModule
/NgIf
.Instead the mock template now uses
@if
syntax if angular is 17 or higher.Fixes #8884