text
stringlengths 0
14.1k
|
---|
iit, |
inject, |
beforeEachBindings, |
it, |
xit, |
TestBed, |
Component, |
View, |
DynamicComponentLoader, |
ElementRef, |
If, |
DirectDomRenderer, |
DOM, |
ImperativeViewComponentUsingNgComponent, |
ChildComp, |
DynamicallyCreatedComponentService, |
DynamicComp, |
DynamicallyCreatedCmp, |
DynamicallyLoaded, |
DynamicallyLoaded2, |
DynamicallyLoadedWithHostProps, |
Location, |
MyComp; |
function main() { |
describe('DynamicComponentLoader', function() { |
describe(""loading into existing location"", (function() { |
it('should work', inject([TestBed, AsyncTestCompleter], (function(tb, async) { |
tb.overrideView(MyComp, new View({ |
template: '<dynamic-comp #dynamic></dynamic-comp>', |
directives: [DynamicComp] |
})); |
tb.createView(MyComp).then((function(view) { |
var dynamicComponent = view.rawView.locals.get(""dynamic""); |
expect(dynamicComponent).toBeAnInstanceOf(DynamicComp); |
dynamicComponent.done.then((function(_) { |
view.detectChanges(); |
expect(view.rootNodes).toHaveText('hello'); |
async.done(); |
})); |
})); |
}))); |
it('should inject dependencies of the dynamically-loaded component', inject([TestBed, AsyncTestCompleter], (function(tb, async) { |
tb.overrideView(MyComp, new View({ |
template: '<dynamic-comp #dynamic></dynamic-comp>', |
directives: [DynamicComp] |
})); |
tb.createView(MyComp).then((function(view) { |
var dynamicComponent = view.rawView.locals.get(""dynamic""); |
dynamicComponent.done.then((function(ref) { |
expect(ref.instance.dynamicallyCreatedComponentService).toBeAnInstanceOf(DynamicallyCreatedComponentService); |
async.done(); |
})); |
})); |
}))); |
it('should allow to destroy and create them via viewcontainer directives', inject([TestBed, AsyncTestCompleter], (function(tb, async) { |
tb.overrideView(MyComp, new View({ |
template: '<div><dynamic-comp #dynamic template=""if: ctxBoolProp""></dynamic-comp></div>', |
directives: [DynamicComp, If] |
})); |
tb.createView(MyComp).then((function(view) { |
view.context.ctxBoolProp = true; |
view.detectChanges(); |
var dynamicComponent = view.rawView.viewContainers[0].views[0].locals.get(""dynamic""); |
dynamicComponent.done.then((function(_) { |
view.detectChanges(); |
expect(view.rootNodes).toHaveText('hello'); |
view.context.ctxBoolProp = false; |
view.detectChanges(); |
expect(view.rawView.viewContainers[0].views.length).toBe(0); |
expect(view.rootNodes).toHaveText(''); |
view.context.ctxBoolProp = true; |
view.detectChanges(); |
var dynamicComponent = view.rawView.viewContainers[0].views[0].locals.get(""dynamic""); |
return dynamicComponent.done; |
})).then((function(_) { |
view.detectChanges(); |
expect(view.rootNodes).toHaveText('hello'); |
async.done(); |
})); |
})); |
}))); |
})); |
describe(""loading next to an existing location"", (function() { |
it('should work', inject([DynamicComponentLoader, TestBed, AsyncTestCompleter], (function(loader, tb, async) { |
tb.overrideView(MyComp, new View({ |
template: '<div><location #loc></location></div>', |
directives: [Location] |
})); |
tb.createView(MyComp).then((function(view) { |
var location = view.rawView.locals.get(""loc""); |
loader.loadNextToExistingLocation(DynamicallyLoaded, location.elementRef).then((function(ref) { |
expect(view.rootNodes).toHaveText(""Location;DynamicallyLoaded;""); |
async.done(); |
})); |
})); |
}))); |
it('should return a disposable component ref', inject([DynamicComponentLoader, TestBed, AsyncTestCompleter], (function(loader, tb, async) { |
tb.overrideView(MyComp, new View({ |
template: '<div><location #loc></location></div>', |
directives: [Location] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.