-
-
Notifications
You must be signed in to change notification settings - Fork 85
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 find instance in case of ng17 control flow
ViewContainerRef actually returns the wrong length in case of Angular 17 Control Flow. By checking that the returned value is not null we should be safe. Solves #7216
- Loading branch information
André Andersson
committed
Apr 12, 2024
1 parent
905f882
commit f6418d7
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
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,47 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, NgModule, VERSION } from '@angular/core'; | ||
|
||
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks'; | ||
|
||
// @see https://github.com/help-me-mom/ng-mocks/issues/7216 | ||
describe('issue-7216', () => { | ||
if (Number.parseInt(VERSION.major, 10) < 17) { | ||
it('needs a17+', () => { | ||
expect(true).toBeTruthy(); | ||
}); | ||
|
||
return; | ||
} | ||
|
||
@Component({ | ||
selector: 'target', | ||
template: ` | ||
@if (hasChild) { | ||
<child></child> | ||
} | ||
`, | ||
}) | ||
class TargetComponent { | ||
public readonly hasChild = true; | ||
} | ||
|
||
@Component({ | ||
selector: 'child', | ||
template: '', | ||
}) | ||
class ChildComponent {} | ||
|
||
@NgModule({ | ||
imports: [CommonModule], | ||
declarations: [TargetComponent, ChildComponent], | ||
}) | ||
class TargetModule {} | ||
|
||
beforeEach(() => MockBuilder(TargetComponent, TargetModule)); | ||
|
||
it('finds child-element', () => { | ||
MockRender(TargetComponent); | ||
|
||
expect(ngMocks.findInstance(ChildComponent)).toBeTruthy(); | ||
}); | ||
}); |