test(ivy): update root causes for @angular/core TestBed failures (#27459)

PR Close #27459
This commit is contained in:
Pawel Kozlowski 2018-12-04 16:30:13 +01:00 committed by Igor Minar
parent 8973f12ee4
commit b25f06ee7c
3 changed files with 116 additions and 106 deletions

View File

@ -82,21 +82,22 @@ import {fixmeIvy} from '@angular/private/testing';
expect(main.nativeElement).toHaveText(''); expect(main.nativeElement).toHaveText('');
}); });
fixmeIvy('unknown') && it('should support multiple content tags', () => { fixmeIvy('FW-789: select attribute on <ng-content> should not be case-sensitive') &&
TestBed.configureTestingModule({declarations: [MultipleContentTagsComponent]}); it('should support multiple content tags', () => {
TestBed.overrideComponent(MainComp, { TestBed.configureTestingModule({declarations: [MultipleContentTagsComponent]});
set: { TestBed.overrideComponent(MainComp, {
template: '<multiple-content-tags>' + set: {
'<div>B</div>' + template: '<multiple-content-tags>' +
'<div>C</div>' + '<div>B</div>' +
'<div class="left">A</div>' + '<div>C</div>' +
'</multiple-content-tags>' '<div class="left">A</div>' +
} '</multiple-content-tags>'
}); }
const main = TestBed.createComponent(MainComp); });
const main = TestBed.createComponent(MainComp);
expect(main.nativeElement).toHaveText('(A, BC)'); expect(main.nativeElement).toHaveText('(A, BC)');
}); });
it('should redistribute only direct children', () => { it('should redistribute only direct children', () => {
TestBed.configureTestingModule({declarations: [MultipleContentTagsComponent]}); TestBed.configureTestingModule({declarations: [MultipleContentTagsComponent]});
@ -184,34 +185,36 @@ import {fixmeIvy} from '@angular/private/testing';
expect(main.nativeElement).toHaveText('OUTER(INNER(INNERINNER(A,BC)))'); expect(main.nativeElement).toHaveText('OUTER(INNER(INNERINNER(A,BC)))');
}); });
fixmeIvy('unknown') && it('should redistribute when the shadow dom changes', () => { fixmeIvy(
TestBed.configureTestingModule( 'FW-745: Compiler isn\'t generating projectionDefs for <ng-content> tags inside <ng-templates>') &&
{declarations: [ConditionalContentComponent, ManualViewportDirective]}); it('should redistribute when the shadow dom changes', () => {
TestBed.overrideComponent(MainComp, { TestBed.configureTestingModule(
set: { {declarations: [ConditionalContentComponent, ManualViewportDirective]});
template: '<conditional-content>' + TestBed.overrideComponent(MainComp, {
'<div class="left">A</div>' + set: {
'<div>B</div>' + template: '<conditional-content>' +
'<div>C</div>' + '<div class="left">A</div>' +
'</conditional-content>' '<div>B</div>' +
} '<div>C</div>' +
}); '</conditional-content>'
const main = TestBed.createComponent(MainComp); }
});
const main = TestBed.createComponent(MainComp);
const viewportDirective = const viewportDirective =
main.debugElement.queryAllNodes(By.directive(ManualViewportDirective))[0].injector.get( main.debugElement.queryAllNodes(By.directive(ManualViewportDirective))[0]
ManualViewportDirective); .injector.get(ManualViewportDirective);
expect(main.nativeElement).toHaveText('(, BC)'); expect(main.nativeElement).toHaveText('(, BC)');
viewportDirective.show(); viewportDirective.show();
main.detectChanges(); main.detectChanges();
expect(main.nativeElement).toHaveText('(A, BC)'); expect(main.nativeElement).toHaveText('(A, BC)');
viewportDirective.hide(); viewportDirective.hide();
main.detectChanges(); main.detectChanges();
expect(main.nativeElement).toHaveText('(, BC)'); expect(main.nativeElement).toHaveText('(, BC)');
}); });
// GH-2095 - https://github.com/angular/angular/issues/2095 // GH-2095 - https://github.com/angular/angular/issues/2095
// important as we are removing the ng-content element during compilation, // important as we are removing the ng-content element during compilation,
@ -478,48 +481,51 @@ import {fixmeIvy} from '@angular/private/testing';
'<cmp-a2>a2<cmp-b21>b21</cmp-b21><cmp-b22>b22</cmp-b22></cmp-a2>'); '<cmp-a2>a2<cmp-b21>b21</cmp-b21><cmp-b22>b22</cmp-b22></cmp-a2>');
}); });
fixmeIvy('unknown') && it('should project filled view containers into a view container', () => { fixmeIvy(
TestBed.configureTestingModule( 'FW-745: Compiler isn\'t generating projectionDefs for <ng-content> tags inside <ng-templates>') &&
{declarations: [ConditionalContentComponent, ManualViewportDirective]}); it('should project filled view containers into a view container', () => {
TestBed.overrideComponent(MainComp, { TestBed.configureTestingModule(
set: { {declarations: [ConditionalContentComponent, ManualViewportDirective]});
template: '<conditional-content>' + TestBed.overrideComponent(MainComp, {
'<div class="left">A</div>' + set: {
'<ng-template manual class="left">B</ng-template>' + template: '<conditional-content>' +
'<div class="left">C</div>' + '<div class="left">A</div>' +
'<div>D</div>' + '<ng-template manual class="left">B</ng-template>' +
'</conditional-content>' '<div class="left">C</div>' +
} '<div>D</div>' +
}); '</conditional-content>'
const main = TestBed.createComponent(MainComp); }
});
const main = TestBed.createComponent(MainComp);
const conditionalComp = main.debugElement.query(By.directive(ConditionalContentComponent)); const conditionalComp =
main.debugElement.query(By.directive(ConditionalContentComponent));
const viewViewportDir = const viewViewportDir =
conditionalComp.queryAllNodes(By.directive(ManualViewportDirective))[0].injector.get( conditionalComp.queryAllNodes(By.directive(ManualViewportDirective))[0].injector.get(
ManualViewportDirective); ManualViewportDirective);
expect(main.nativeElement).toHaveText('(, D)'); expect(main.nativeElement).toHaveText('(, D)');
expect(main.nativeElement).toHaveText('(, D)'); expect(main.nativeElement).toHaveText('(, D)');
viewViewportDir.show(); viewViewportDir.show();
main.detectChanges(); main.detectChanges();
expect(main.nativeElement).toHaveText('(AC, D)'); expect(main.nativeElement).toHaveText('(AC, D)');
const contentViewportDir = const contentViewportDir =
conditionalComp.queryAllNodes(By.directive(ManualViewportDirective))[1].injector.get( conditionalComp.queryAllNodes(By.directive(ManualViewportDirective))[1].injector.get(
ManualViewportDirective); ManualViewportDirective);
contentViewportDir.show(); contentViewportDir.show();
main.detectChanges(); main.detectChanges();
expect(main.nativeElement).toHaveText('(ABC, D)'); expect(main.nativeElement).toHaveText('(ABC, D)');
// hide view viewport, and test that it also hides // hide view viewport, and test that it also hides
// the content viewport's views // the content viewport's views
viewViewportDir.hide(); viewViewportDir.hide();
main.detectChanges(); main.detectChanges();
expect(main.nativeElement).toHaveText('(, D)'); expect(main.nativeElement).toHaveText('(, D)');
}); });
}); });
} }

View File

@ -74,7 +74,7 @@ function declareTests(config?: {useJit: boolean}) {
expect(CountingPipe.calls).toBe(1); expect(CountingPipe.calls).toBe(1);
}); });
fixmeIvy('unknown') && fixmeIvy('FW-756: Pipes and directives from imported modules are not taken into account') &&
it('should only update the bound property when using asyncPipe - #15205', it('should only update the bound property when using asyncPipe - #15205',
fakeAsync(() => { fakeAsync(() => {
@Component({template: '<div myDir [a]="p | async" [b]="2"></div>'}) @Component({template: '<div myDir [a]="p | async" [b]="2"></div>'})

View File

@ -52,27 +52,30 @@ function declareTests(config?: {useJit: boolean}) {
afterEach(() => { getDOM().log = originalLog; }); afterEach(() => { getDOM().log = originalLog; });
describe('events', () => { describe('events', () => {
fixmeIvy('unknown') && it('should disallow binding to attr.on*', () => { fixmeIvy('FW-787: Exception in template parsing leaves TestBed in corrupted state') &&
const template = `<div [attr.onclick]="ctxProp"></div>`; it('should disallow binding to attr.on*', () => {
TestBed.overrideComponent(SecuredComponent, {set: {template}}); const template = `<div [attr.onclick]="ctxProp"></div>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
expect(() => TestBed.createComponent(SecuredComponent)) expect(() => TestBed.createComponent(SecuredComponent))
.toThrowError( .toThrowError(
/Binding to event attribute 'onclick' is disallowed for security reasons, please use \(click\)=.../); /Binding to event attribute 'onclick' is disallowed for security reasons, please use \(click\)=.../);
}); });
fixmeIvy('unknown') && it('should disallow binding to on* with NO_ERRORS_SCHEMA', () => { fixmeIvy('FW-787: Exception in template parsing leaves TestBed in corrupted state') &&
const template = `<div [onclick]="ctxProp"></div>`; it('should disallow binding to on* with NO_ERRORS_SCHEMA', () => {
TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({ const template = `<div [onclick]="ctxProp"></div>`;
schemas: [NO_ERRORS_SCHEMA] TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({
}); schemas: [NO_ERRORS_SCHEMA]
});
expect(() => TestBed.createComponent(SecuredComponent)) expect(() => TestBed.createComponent(SecuredComponent))
.toThrowError( .toThrowError(
/Binding to event property 'onclick' is disallowed for security reasons, please use \(click\)=.../); /Binding to event property 'onclick' is disallowed for security reasons, please use \(click\)=.../);
}); });
fixmeIvy('unknown') && fixmeIvy(
'FW-786: Element properties and directive inputs are not distinguished for sanitisation purposes') &&
it('should disallow binding to on* unless it is consumed by a directive', () => { it('should disallow binding to on* unless it is consumed by a directive', () => {
const template = `<div [onPrefixedProp]="ctxProp" [onclick]="ctxProp"></div>`; const template = `<div [onPrefixedProp]="ctxProp" [onclick]="ctxProp"></div>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({ TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({
@ -95,7 +98,7 @@ function declareTests(config?: {useJit: boolean}) {
}); });
describe('safe HTML values', function() { describe('safe HTML values', function() {
fixmeIvy('unknown') && it('should not escape values marked as trusted', () => { it('should not escape values marked as trusted', () => {
const template = `<a [href]="ctxProp">Link Title</a>`; const template = `<a [href]="ctxProp">Link Title</a>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}}); TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent); const fixture = TestBed.createComponent(SecuredComponent);
@ -109,7 +112,7 @@ function declareTests(config?: {useJit: boolean}) {
expect(getDOM().getProperty(e, 'href')).toEqual('javascript:alert(1)'); expect(getDOM().getProperty(e, 'href')).toEqual('javascript:alert(1)');
}); });
fixmeIvy('unknown') && it('should error when using the wrong trusted value', () => { it('should error when using the wrong trusted value', () => {
const template = `<a [href]="ctxProp">Link Title</a>`; const template = `<a [href]="ctxProp">Link Title</a>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}}); TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent); const fixture = TestBed.createComponent(SecuredComponent);
@ -121,7 +124,7 @@ function declareTests(config?: {useJit: boolean}) {
expect(() => fixture.detectChanges()).toThrowError(/Required a safe URL, got a Script/); expect(() => fixture.detectChanges()).toThrowError(/Required a safe URL, got a Script/);
}); });
fixmeIvy('unknown') && it('should warn when using in string interpolation', () => { it('should warn when using in string interpolation', () => {
const template = `<a href="/foo/{{ctxProp}}">Link Title</a>`; const template = `<a href="/foo/{{ctxProp}}">Link Title</a>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}}); TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent); const fixture = TestBed.createComponent(SecuredComponent);
@ -154,7 +157,7 @@ function declareTests(config?: {useJit: boolean}) {
expect(value).toEqual('unsafe:javascript:alert(1)'); expect(value).toEqual('unsafe:javascript:alert(1)');
} }
fixmeIvy('unknown') && it('should escape unsafe properties', () => { it('should escape unsafe properties', () => {
const template = `<a [href]="ctxProp">Link Title</a>`; const template = `<a [href]="ctxProp">Link Title</a>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}}); TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent); const fixture = TestBed.createComponent(SecuredComponent);
@ -162,7 +165,7 @@ function declareTests(config?: {useJit: boolean}) {
checkEscapeOfHrefProperty(fixture, false); checkEscapeOfHrefProperty(fixture, false);
}); });
fixmeIvy('unknown') && it('should escape unsafe attributes', () => { it('should escape unsafe attributes', () => {
const template = `<a [attr.href]="ctxProp">Link Title</a>`; const template = `<a [attr.href]="ctxProp">Link Title</a>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}}); TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent); const fixture = TestBed.createComponent(SecuredComponent);
@ -170,7 +173,7 @@ function declareTests(config?: {useJit: boolean}) {
checkEscapeOfHrefProperty(fixture, true); checkEscapeOfHrefProperty(fixture, true);
}); });
fixmeIvy('unknown') && fixmeIvy('FW-785: Host bindings are not sanitised') &&
it('should escape unsafe properties if they are used in host bindings', () => { it('should escape unsafe properties if they are used in host bindings', () => {
@Directive({selector: '[dirHref]'}) @Directive({selector: '[dirHref]'})
class HrefDirective { class HrefDirective {
@ -187,7 +190,7 @@ function declareTests(config?: {useJit: boolean}) {
checkEscapeOfHrefProperty(fixture, false); checkEscapeOfHrefProperty(fixture, false);
}); });
fixmeIvy('unknown') && fixmeIvy('FW-785: Host bindings are not sanitised') &&
it('should escape unsafe attributes if they are used in host bindings', () => { it('should escape unsafe attributes if they are used in host bindings', () => {
@Directive({selector: '[dirHref]'}) @Directive({selector: '[dirHref]'})
class HrefDirective { class HrefDirective {
@ -204,7 +207,7 @@ function declareTests(config?: {useJit: boolean}) {
checkEscapeOfHrefProperty(fixture, true); checkEscapeOfHrefProperty(fixture, true);
}); });
fixmeIvy('unknown') && it('should escape unsafe style values', () => { it('should escape unsafe style values', () => {
const template = `<div [style.background]="ctxProp">Text</div>`; const template = `<div [style.background]="ctxProp">Text</div>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}}); TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent); const fixture = TestBed.createComponent(SecuredComponent);
@ -224,15 +227,16 @@ function declareTests(config?: {useJit: boolean}) {
expect(getDOM().getStyle(e, 'background')).not.toContain('javascript'); expect(getDOM().getStyle(e, 'background')).not.toContain('javascript');
}); });
fixmeIvy('unknown') && it('should escape unsafe SVG attributes', () => { fixmeIvy('FW-787: Exception in template parsing leaves TestBed in corrupted state') &&
const template = `<svg:circle [xlink:href]="ctxProp">Text</svg:circle>`; it('should escape unsafe SVG attributes', () => {
TestBed.overrideComponent(SecuredComponent, {set: {template}}); const template = `<svg:circle [xlink:href]="ctxProp">Text</svg:circle>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
expect(() => TestBed.createComponent(SecuredComponent)) expect(() => TestBed.createComponent(SecuredComponent))
.toThrowError(/Can't bind to 'xlink:href'/); .toThrowError(/Can't bind to 'xlink:href'/);
}); });
fixmeIvy('unknown') && it('should escape unsafe HTML values', () => { it('should escape unsafe HTML values', () => {
const template = `<div [innerHTML]="ctxProp">Text</div>`; const template = `<div [innerHTML]="ctxProp">Text</div>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}}); TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent); const fixture = TestBed.createComponent(SecuredComponent);