forked from help-me-mom/ng-mocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: unable to bind ngIf in angular 17+
Use new angular control flow to avoid missing directive while mocking child templates Solves help-me-mom#8884
- Loading branch information
1 parent
cbbaec9
commit bf009eb
Showing
2 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
12 changes: 9 additions & 3 deletions
12
libs/ng-mocks/src/lib/mock-component/render/generate-template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
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(); | ||
|
||
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') | ||
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 avaiable to a component in a module', () => { | ||
@Component({ | ||
selector: 'app-target', | ||
template: `<ng-template [ngTemplateOutlet]="content" />`, | ||
}) | ||
class TargetComponent { | ||
@ContentChild('content') | ||
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(); | ||
}); | ||
}); | ||
}); |