mirror of https://github.com/abpframework/abp.git
3 changed files with 55 additions and 7 deletions
@ -0,0 +1,12 @@ |
|||
import { Component, ViewChild, ViewContainerRef } from '@angular/core'; |
|||
|
|||
@Component({ |
|||
selector: 'abp-modal-container', |
|||
template: ` |
|||
<ng-container #container></ng-container> |
|||
`,
|
|||
}) |
|||
export class ModalContainerComponent { |
|||
@ViewChild('container', { static: true, read: ViewContainerRef }) |
|||
container: ViewContainerRef; |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
import { Component, ComponentFactoryResolver, ComponentRef } from '@angular/core'; |
|||
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; |
|||
import { ModalContainerComponent } from '../components/modal/modal-container.component'; |
|||
|
|||
describe('ModalContainerComponent', () => { |
|||
@Component({ template: '<div class="foo">bar</div>' }) |
|||
class TestComponent {} |
|||
|
|||
let componentRef: ComponentRef<TestComponent>; |
|||
let spectator: Spectator<ModalContainerComponent>; |
|||
|
|||
const createComponent = createComponentFactory({ |
|||
component: ModalContainerComponent, |
|||
entryComponents: [TestComponent], |
|||
}); |
|||
|
|||
beforeEach(() => (spectator = createComponent())); |
|||
|
|||
afterEach(() => componentRef.destroy()); |
|||
|
|||
describe('#container', () => { |
|||
it('should be a ViewContainerRef', () => { |
|||
let foo = document.querySelector('div.foo'); |
|||
expect(foo).toBeNull(); |
|||
|
|||
const cfResolver = spectator.get(ComponentFactoryResolver); |
|||
const factory = cfResolver.resolveComponentFactory(TestComponent); |
|||
componentRef = spectator.component.container.createComponent(factory); |
|||
|
|||
foo = document.querySelector('div.foo'); |
|||
expect(foo.textContent).toBe('bar'); |
|||
}); |
|||
}); |
|||
}); |
|||
Loading…
Reference in new issue