forked from help-me-mom/ng-mocks
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#333): register mock components with entryComponents
- Loading branch information
Showing
3 changed files
with
91 additions
and
18 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
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,56 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, NgModule, Type } from '@angular/core'; | ||
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks'; | ||
|
||
@Component({ | ||
selector: 'dynamic-overlay', | ||
template: | ||
'<ng-container *ngComponentOutlet="component"></ng-container>', | ||
}) | ||
export class DynamicOverlayComponent { | ||
public component?: Type<any>; | ||
|
||
public attachComponent(component: Type<any>) { | ||
this.component = component; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [DynamicOverlayComponent], | ||
exports: [DynamicOverlayComponent], | ||
imports: [CommonModule], | ||
}) | ||
export class OverlayModule {} | ||
|
||
@Component({ | ||
selector: 'mock-component', | ||
template: '<h1>previous</h1>', | ||
}) | ||
class MockComponent {} | ||
|
||
describe('issue-333', () => { | ||
// this should work with and without ivy | ||
beforeEach(() => | ||
MockBuilder(DynamicOverlayComponent, OverlayModule).keep( | ||
MockComponent, | ||
), | ||
); | ||
|
||
it('should render', () => { | ||
const fixture = MockRender(DynamicOverlayComponent); | ||
|
||
expect(ngMocks.formatHtml(fixture)).toEqual( | ||
`<dynamic-overlay></dynamic-overlay>`, | ||
); | ||
}); | ||
|
||
it('should project content', () => { | ||
const fixture = MockRender(DynamicOverlayComponent); | ||
fixture.point.componentInstance.attachComponent(MockComponent); | ||
fixture.detectChanges(); | ||
|
||
expect(ngMocks.formatHtml(fixture)).toEqual( | ||
`<dynamic-overlay><mock-component><h1>previous</h1></mock-component></dynamic-overlay>`, | ||
); | ||
}); | ||
}); |