|
|
@ -10,7 +10,7 @@ import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, Compon
|
|
|
|
import {ComponentFixture, TestBed, fakeAsync} from '@angular/core/testing';
|
|
|
|
import {ComponentFixture, TestBed, fakeAsync} from '@angular/core/testing';
|
|
|
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
|
|
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
|
|
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
|
|
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
|
|
|
import {fixmeIvy} from '@angular/private/testing';
|
|
|
|
import {fixmeIvy, obsoleteInIvy, onlyInIvy} from '@angular/private/testing';
|
|
|
|
|
|
|
|
|
|
|
|
@Directive({selector: '[simpleDirective]'})
|
|
|
|
@Directive({selector: '[simpleDirective]'})
|
|
|
|
class SimpleDirective {
|
|
|
|
class SimpleDirective {
|
|
|
@ -598,18 +598,27 @@ class TestComp {
|
|
|
|
expect(el.children[0].injector.get(NeedsAppService).service).toEqual('appService');
|
|
|
|
expect(el.children[0].injector.get(NeedsAppService).service).toEqual('appService');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fixmeIvy('unknown').it('should not instantiate a directive with cyclic dependencies', () => {
|
|
|
|
obsoleteInIvy('This error is no longer generated by the compiler')
|
|
|
|
|
|
|
|
.it('should not instantiate a directive with cyclic dependencies', () => {
|
|
|
|
TestBed.configureTestingModule({declarations: [CycleDirective]});
|
|
|
|
TestBed.configureTestingModule({declarations: [CycleDirective]});
|
|
|
|
expect(() => createComponent('<div cycleDirective></div>'))
|
|
|
|
expect(() => createComponent('<div cycleDirective></div>'))
|
|
|
|
.toThrowError(
|
|
|
|
.toThrowError(
|
|
|
|
/Template parse errors:\nCannot instantiate cyclic dependency! CycleDirective \("\[ERROR ->\]<div cycleDirective><\/div>"\): .*TestComp.html@0:0/);
|
|
|
|
/Template parse errors:\nCannot instantiate cyclic dependency! CycleDirective \("\[ERROR ->\]<div cycleDirective><\/div>"\): .*TestComp.html@0:0/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fixmeIvy('unknown').it(
|
|
|
|
onlyInIvy('This error is generated by the runtime of Ivy')
|
|
|
|
'should not instantiate a directive in a view that has a host dependency on providers' +
|
|
|
|
.it('should not instantiate a directive with cyclic dependencies', () => {
|
|
|
|
|
|
|
|
TestBed.configureTestingModule({declarations: [CycleDirective]});
|
|
|
|
|
|
|
|
expect(() => createComponent('<div cycleDirective></div>'))
|
|
|
|
|
|
|
|
.toThrowError('Circular dep for CycleDirective');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
obsoleteInIvy('This error is no longer generated by the compiler')
|
|
|
|
|
|
|
|
.it('should not instantiate a directive in a view that has a host dependency on providers' +
|
|
|
|
' of the component',
|
|
|
|
' of the component',
|
|
|
|
() => {
|
|
|
|
() => {
|
|
|
|
TestBed.configureTestingModule({declarations: [SimpleComponent, NeedsServiceFromHost]});
|
|
|
|
TestBed.configureTestingModule(
|
|
|
|
|
|
|
|
{declarations: [SimpleComponent, NeedsServiceFromHost]});
|
|
|
|
TestBed.overrideComponent(
|
|
|
|
TestBed.overrideComponent(
|
|
|
|
SimpleComponent,
|
|
|
|
SimpleComponent,
|
|
|
|
{set: {providers: [{provide: 'service', useValue: 'hostService'}]}});
|
|
|
|
{set: {providers: [{provide: 'service', useValue: 'hostService'}]}});
|
|
|
@ -621,8 +630,24 @@ class TestComp {
|
|
|
|
/Template parse errors:\nNo provider for service \("\[ERROR ->\]<div needsServiceFromHost><div>"\): .*SimpleComponent.html@0:0/);
|
|
|
|
/Template parse errors:\nNo provider for service \("\[ERROR ->\]<div needsServiceFromHost><div>"\): .*SimpleComponent.html@0:0/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fixmeIvy('unknown').it(
|
|
|
|
onlyInIvy('This error is generated by the runtime of Ivy')
|
|
|
|
'should not instantiate a directive in a view that has a host dependency on providers' +
|
|
|
|
.it('should not instantiate a directive in a view that has a host dependency on providers' +
|
|
|
|
|
|
|
|
' of the component',
|
|
|
|
|
|
|
|
() => {
|
|
|
|
|
|
|
|
TestBed.configureTestingModule(
|
|
|
|
|
|
|
|
{declarations: [SimpleComponent, NeedsServiceFromHost]});
|
|
|
|
|
|
|
|
TestBed.overrideComponent(
|
|
|
|
|
|
|
|
SimpleComponent,
|
|
|
|
|
|
|
|
{set: {providers: [{provide: 'service', useValue: 'hostService'}]}});
|
|
|
|
|
|
|
|
TestBed.overrideComponent(
|
|
|
|
|
|
|
|
SimpleComponent, {set: {template: '<div needsServiceFromHost><div>'}});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(() => createComponent('<div simpleComponent></div>'))
|
|
|
|
|
|
|
|
.toThrowError('NodeInjector: NOT_FOUND [service]');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
obsoleteInIvy('This error is no longer generated by the compiler')
|
|
|
|
|
|
|
|
.it('should not instantiate a directive in a view that has a host dependency on providers' +
|
|
|
|
' of a decorator directive',
|
|
|
|
' of a decorator directive',
|
|
|
|
() => {
|
|
|
|
() => {
|
|
|
|
TestBed.configureTestingModule(
|
|
|
|
TestBed.configureTestingModule(
|
|
|
@ -638,8 +663,24 @@ class TestComp {
|
|
|
|
/Template parse errors:\nNo provider for service \("\[ERROR ->\]<div needsServiceFromHost><div>"\): .*SimpleComponent.html@0:0/);
|
|
|
|
/Template parse errors:\nNo provider for service \("\[ERROR ->\]<div needsServiceFromHost><div>"\): .*SimpleComponent.html@0:0/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fixmeIvy('unknown').it(
|
|
|
|
onlyInIvy('This error is generated by the runtime of Ivy')
|
|
|
|
'should not instantiate a directive in a view that has a self dependency on a parent directive',
|
|
|
|
.it('should not instantiate a directive in a view that has a host dependency on providers' +
|
|
|
|
|
|
|
|
' of a decorator directive',
|
|
|
|
|
|
|
|
() => {
|
|
|
|
|
|
|
|
TestBed.configureTestingModule(
|
|
|
|
|
|
|
|
{declarations: [SimpleComponent, SomeOtherDirective, NeedsServiceFromHost]});
|
|
|
|
|
|
|
|
TestBed.overrideComponent(
|
|
|
|
|
|
|
|
SimpleComponent,
|
|
|
|
|
|
|
|
{set: {providers: [{provide: 'service', useValue: 'hostService'}]}});
|
|
|
|
|
|
|
|
TestBed.overrideComponent(
|
|
|
|
|
|
|
|
SimpleComponent, {set: {template: '<div needsServiceFromHost><div>'}});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(() => createComponent('<div simpleComponent someOtherDirective></div>'))
|
|
|
|
|
|
|
|
.toThrowError('NodeInjector: NOT_FOUND [service]');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
obsoleteInIvy('This error is no longer generated by the compiler')
|
|
|
|
|
|
|
|
.it('should not instantiate a directive in a view that has a self dependency on a parent directive',
|
|
|
|
() => {
|
|
|
|
() => {
|
|
|
|
TestBed.configureTestingModule(
|
|
|
|
TestBed.configureTestingModule(
|
|
|
|
{declarations: [SimpleDirective, NeedsDirectiveFromSelf]});
|
|
|
|
{declarations: [SimpleDirective, NeedsDirectiveFromSelf]});
|
|
|
@ -650,6 +691,17 @@ class TestComp {
|
|
|
|
/Template parse errors:\nNo provider for SimpleDirective \("<div simpleDirective>\[ERROR ->\]<div needsDirectiveFromSelf><\/div><\/div>"\): .*TestComp.html@0:21/);
|
|
|
|
/Template parse errors:\nNo provider for SimpleDirective \("<div simpleDirective>\[ERROR ->\]<div needsDirectiveFromSelf><\/div><\/div>"\): .*TestComp.html@0:21/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onlyInIvy('This error is generated by the runtime of Ivy')
|
|
|
|
|
|
|
|
.it('should not instantiate a directive in a view that has a self dependency on a parent directive',
|
|
|
|
|
|
|
|
() => {
|
|
|
|
|
|
|
|
TestBed.configureTestingModule(
|
|
|
|
|
|
|
|
{declarations: [SimpleDirective, NeedsDirectiveFromSelf]});
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
|
|
|
() => createComponent(
|
|
|
|
|
|
|
|
'<div simpleDirective><div needsDirectiveFromSelf></div></div>'))
|
|
|
|
|
|
|
|
.toThrowError('NodeInjector: NOT_FOUND [SimpleDirective]');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should instantiate directives that depend on other directives', fakeAsync(() => {
|
|
|
|
it('should instantiate directives that depend on other directives', fakeAsync(() => {
|
|
|
|
TestBed.configureTestingModule({declarations: [SimpleDirective, NeedsDirective]});
|
|
|
|
TestBed.configureTestingModule({declarations: [SimpleDirective, NeedsDirective]});
|
|
|
|
const el = createComponent('<div simpleDirective><div needsDirective></div></div>');
|
|
|
|
const el = createComponent('<div simpleDirective><div needsDirective></div></div>');
|
|
|
@ -691,8 +743,8 @@ class TestComp {
|
|
|
|
expect(el.componentInstance.service).toEqual('appService');
|
|
|
|
expect(el.componentInstance.service).toEqual('appService');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fixmeIvy('unknown').it(
|
|
|
|
obsoleteInIvy('This error is no longer generated by the compiler')
|
|
|
|
'should not instantiate directives that depend on other directives on the host element',
|
|
|
|
.it('should not instantiate directives that depend on other directives on the host element',
|
|
|
|
() => {
|
|
|
|
() => {
|
|
|
|
TestBed.configureTestingModule(
|
|
|
|
TestBed.configureTestingModule(
|
|
|
|
{declarations: [SimpleComponent, SimpleDirective, NeedsDirectiveFromHost]});
|
|
|
|
{declarations: [SimpleComponent, SimpleDirective, NeedsDirectiveFromHost]});
|
|
|
@ -703,6 +755,17 @@ class TestComp {
|
|
|
|
/Template parse errors:\nNo provider for SimpleDirective \("\[ERROR ->\]<div needsDirectiveFromHost><\/div>"\): .*SimpleComponent.html@0:0/);
|
|
|
|
/Template parse errors:\nNo provider for SimpleDirective \("\[ERROR ->\]<div needsDirectiveFromHost><\/div>"\): .*SimpleComponent.html@0:0/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onlyInIvy('This error is generated by the runtime of Ivy')
|
|
|
|
|
|
|
|
.it('should not instantiate directives that depend on other directives on the host element',
|
|
|
|
|
|
|
|
() => {
|
|
|
|
|
|
|
|
TestBed.configureTestingModule(
|
|
|
|
|
|
|
|
{declarations: [SimpleComponent, SimpleDirective, NeedsDirectiveFromHost]});
|
|
|
|
|
|
|
|
TestBed.overrideComponent(
|
|
|
|
|
|
|
|
SimpleComponent, {set: {template: '<div needsDirectiveFromHost></div>'}});
|
|
|
|
|
|
|
|
expect(() => createComponent('<div simpleComponent simpleDirective></div>'))
|
|
|
|
|
|
|
|
.toThrowError('NodeInjector: NOT_FOUND [SimpleDirective]');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fixmeIvy('unknown').it(
|
|
|
|
fixmeIvy('unknown').it(
|
|
|
|
'should allow to use the NgModule injector from a root ViewContainerRef.parentInjector',
|
|
|
|
'should allow to use the NgModule injector from a root ViewContainerRef.parentInjector',
|
|
|
|
() => {
|
|
|
|
() => {
|
|
|
@ -884,7 +947,7 @@ class TestComp {
|
|
|
|
.toEqual(el.childNodes[0].injector.get(NeedsViewContainerRef).viewContainer.element);
|
|
|
|
.toEqual(el.childNodes[0].injector.get(NeedsViewContainerRef).viewContainer.element);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fixmeIvy('unknown').it('should throw if there is no TemplateRef', () => {
|
|
|
|
it('should throw if there is no TemplateRef', () => {
|
|
|
|
TestBed.configureTestingModule({declarations: [NeedsTemplateRef]});
|
|
|
|
TestBed.configureTestingModule({declarations: [NeedsTemplateRef]});
|
|
|
|
expect(() => createComponent('<div needsTemplateRef></div>'))
|
|
|
|
expect(() => createComponent('<div needsTemplateRef></div>'))
|
|
|
|
.toThrowError(/No provider for TemplateRef!/);
|
|
|
|
.toThrowError(/No provider for TemplateRef!/);
|
|
|
|