test: move remaining fixmeIvy to test level (#27354)

Moves all of the remaning `describe`-level fixme instances to the `it` level.

PR Close #27354
This commit is contained in:
Kristiyan Kostadinov
2018-11-29 21:28:01 -08:00
committed by Igor Minar
parent 36e7bf1b7b
commit 23bc8edf24
11 changed files with 1566 additions and 1451 deletions
File diff suppressed because it is too large Load Diff
+15 -15
View File
@@ -169,7 +169,7 @@ class TestApp {
}
{
fixmeIvy('unknown') && describe('debug element', () => {
describe('debug element', () => {
let fixture: ComponentFixture<any>;
beforeEach(async(() => {
@@ -192,13 +192,13 @@ class TestApp {
});
}));
it('should list all child nodes', () => {
fixmeIvy('unknown') && it('should list all child nodes', () => {
fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges();
expect(fixture.debugElement.childNodes.length).toEqual(3);
});
it('should list all component child elements', () => {
fixmeIvy('unknown') && it('should list all component child elements', () => {
fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges();
const childEls = fixture.debugElement.children;
@@ -225,7 +225,7 @@ class TestApp {
expect(getDOM().hasClass(childNested[0].nativeElement, 'childnested')).toBe(true);
});
it('should list conditional component child elements', () => {
fixmeIvy('unknown') && it('should list conditional component child elements', () => {
fixture = TestBed.createComponent(ConditionalParentComp);
fixture.detectChanges();
@@ -246,7 +246,7 @@ class TestApp {
expect(conditionalContentComp.children.length).toEqual(1);
});
it('should list child elements within viewports', () => {
fixmeIvy('unknown') && it('should list child elements within viewports', () => {
fixture = TestBed.createComponent(UsingFor);
fixture.detectChanges();
@@ -259,7 +259,7 @@ class TestApp {
expect(list.children.length).toEqual(3);
});
it('should list element attributes', () => {
fixmeIvy('unknown') && it('should list element attributes', () => {
fixture = TestBed.createComponent(TestApp);
fixture.detectChanges();
const bankElem = fixture.debugElement.children[0];
@@ -268,7 +268,7 @@ class TestApp {
expect(bankElem.attributes['account']).toEqual('4747');
});
it('should list element classes', () => {
fixmeIvy('unknown') && it('should list element classes', () => {
fixture = TestBed.createComponent(TestApp);
fixture.detectChanges();
const bankElem = fixture.debugElement.children[0];
@@ -277,7 +277,7 @@ class TestApp {
expect(bankElem.classes['open']).toBe(false);
});
it('should list element styles', () => {
fixmeIvy('unknown') && it('should list element styles', () => {
fixture = TestBed.createComponent(TestApp);
fixture.detectChanges();
const bankElem = fixture.debugElement.children[0];
@@ -286,7 +286,7 @@ class TestApp {
expect(bankElem.styles['color']).toEqual('red');
});
it('should query child elements by css', () => {
fixmeIvy('unknown') && it('should query child elements by css', () => {
fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges();
@@ -296,7 +296,7 @@ class TestApp {
expect(getDOM().hasClass(childTestEls[0].nativeElement, 'child-comp-class')).toBe(true);
});
it('should query child elements by directive', () => {
fixmeIvy('unknown') && it('should query child elements by directive', () => {
fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges();
@@ -309,21 +309,21 @@ class TestApp {
expect(getDOM().hasClass(childTestEls[3].nativeElement, 'childnested')).toBe(true);
});
it('should list providerTokens', () => {
fixmeIvy('unknown') && it('should list providerTokens', () => {
fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges();
expect(fixture.debugElement.providerTokens).toContain(Logger);
});
it('should list locals', () => {
fixmeIvy('unknown') && it('should list locals', () => {
fixture = TestBed.createComponent(LocalsComp);
fixture.detectChanges();
expect(fixture.debugElement.children[0].references !['alice']).toBeAnInstanceOf(MyDir);
});
it('should allow injecting from the element injector', () => {
fixmeIvy('unknown') && it('should allow injecting from the element injector', () => {
fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges();
@@ -332,7 +332,7 @@ class TestApp {
]);
});
it('should list event listeners', () => {
fixmeIvy('unknown') && it('should list event listeners', () => {
fixture = TestBed.createComponent(EventsComp);
fixture.detectChanges();
@@ -341,7 +341,7 @@ class TestApp {
});
it('should trigger event handlers', () => {
fixmeIvy('unknown') && it('should trigger event handlers', () => {
fixture = TestBed.createComponent(EventsComp);
fixture.detectChanges();
@@ -13,7 +13,7 @@ import {Log} from '@angular/core/testing/src/testing_internal';
import {fixmeIvy} from '@angular/private/testing';
{
fixmeIvy('unknown') && describe('directive lifecycle integration spec', () => {
describe('directive lifecycle integration spec', () => {
let log: Log;
beforeEach(() => {
@@ -31,22 +31,23 @@ import {fixmeIvy} from '@angular/private/testing';
beforeEach(inject([Log], (_log: any) => { log = _log; }));
it('should invoke lifecycle methods ngOnChanges > ngOnInit > ngDoCheck > ngAfterContentChecked',
() => {
const fixture = TestBed.createComponent(MyComp5);
fixture.detectChanges();
fixmeIvy('unknown') &&
it('should invoke lifecycle methods ngOnChanges > ngOnInit > ngDoCheck > ngAfterContentChecked',
() => {
const fixture = TestBed.createComponent(MyComp5);
fixture.detectChanges();
expect(log.result())
.toEqual(
'ngOnChanges; ngOnInit; ngDoCheck; ngAfterContentInit; ngAfterContentChecked; child_ngDoCheck; ' +
'ngAfterViewInit; ngAfterViewChecked');
expect(log.result())
.toEqual(
'ngOnChanges; ngOnInit; ngDoCheck; ngAfterContentInit; ngAfterContentChecked; child_ngDoCheck; ' +
'ngAfterViewInit; ngAfterViewChecked');
log.clear();
fixture.detectChanges();
log.clear();
fixture.detectChanges();
expect(log.result())
.toEqual('ngDoCheck; ngAfterContentChecked; child_ngDoCheck; ngAfterViewChecked');
});
expect(log.result())
.toEqual('ngDoCheck; ngAfterContentChecked; child_ngDoCheck; ngAfterViewChecked');
});
});
}
File diff suppressed because it is too large Load Diff
@@ -13,15 +13,17 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
import {fixmeIvy} from '@angular/private/testing';
{
fixmeIvy('unknown') && describe('forwardRef integration', function() {
describe('forwardRef integration', function() {
beforeEach(() => { TestBed.configureTestingModule({imports: [Module], declarations: [App]}); });
it('should instantiate components which are declared using forwardRef', () => {
const a = TestBed.configureTestingModule({schemas: [NO_ERRORS_SCHEMA]}).createComponent(App);
a.detectChanges();
expect(asNativeElements(a.debugElement.children)).toHaveText('frame(lock)');
expect(TestBed.get(ModuleFrame)).toBeDefined();
});
fixmeIvy('unknown') &&
it('should instantiate components which are declared using forwardRef', () => {
const a =
TestBed.configureTestingModule({schemas: [NO_ERRORS_SCHEMA]}).createComponent(App);
a.detectChanges();
expect(asNativeElements(a.debugElement.children)).toHaveText('frame(lock)');
expect(TestBed.get(ModuleFrame)).toBeDefined();
});
});
}
@@ -16,7 +16,7 @@ import {fixmeIvy} from '@angular/private/testing';
{
// ivy fix in https://github.com/angular/angular/pull/26871
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && describe('Jit Summaries', () => {
describe('Jit Summaries', () => {
let instances: Map<any, Base>;
let summaries: () => any[];
@@ -138,146 +138,160 @@ import {fixmeIvy} from '@angular/private/testing';
afterEach(() => { resetTestEnvironmentWithSummaries(); });
it('should use directive metadata from summaries', () => {
resetTestEnvironmentWithSummaries(summaries);
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
it('should use directive metadata from summaries', () => {
resetTestEnvironmentWithSummaries(summaries);
@Component({template: '<div someDir></div>'})
class TestComp {
}
@Component({template: '<div someDir></div>'})
class TestComp {
}
TestBed
.configureTestingModule({providers: [SomeDep], declarations: [TestComp, SomeDirective]})
.createComponent(TestComp);
expectInstanceCreated(SomeDirective);
});
TestBed
.configureTestingModule(
{providers: [SomeDep], declarations: [TestComp, SomeDirective]})
.createComponent(TestComp);
expectInstanceCreated(SomeDirective);
});
it('should use pipe metadata from summaries', () => {
resetTestEnvironmentWithSummaries(summaries);
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
it('should use pipe metadata from summaries', () => {
resetTestEnvironmentWithSummaries(summaries);
@Component({template: '{{1 | somePipe}}'})
class TestComp {
}
@Component({template: '{{1 | somePipe}}'})
class TestComp {
}
TestBed.configureTestingModule({providers: [SomeDep], declarations: [TestComp, SomePipe]})
.createComponent(TestComp);
expectInstanceCreated(SomePipe);
});
TestBed.configureTestingModule({providers: [SomeDep], declarations: [TestComp, SomePipe]})
.createComponent(TestComp);
expectInstanceCreated(SomePipe);
});
it('should use Service metadata from summaries', () => {
resetTestEnvironmentWithSummaries(summaries);
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
it('should use Service metadata from summaries', () => {
resetTestEnvironmentWithSummaries(summaries);
TestBed.configureTestingModule({
providers: [SomeService, SomeDep],
});
TestBed.get(SomeService);
expectInstanceCreated(SomeService);
});
TestBed.configureTestingModule({
providers: [SomeService, SomeDep],
});
TestBed.get(SomeService);
expectInstanceCreated(SomeService);
});
it('should use NgModule metadata from summaries', () => {
resetTestEnvironmentWithSummaries(summaries);
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
it('should use NgModule metadata from summaries', () => {
resetTestEnvironmentWithSummaries(summaries);
TestBed
.configureTestingModule(
{providers: [SomeDep], declarations: [TestComp3], imports: [SomeModule]})
.createComponent(TestComp3);
TestBed
.configureTestingModule(
{providers: [SomeDep], declarations: [TestComp3], imports: [SomeModule]})
.createComponent(TestComp3);
expectInstanceCreated(SomeModule);
expectInstanceCreated(SomeDirective);
expectInstanceCreated(SomePipe);
expectInstanceCreated(SomeService);
});
expectInstanceCreated(SomeModule);
expectInstanceCreated(SomeDirective);
expectInstanceCreated(SomePipe);
expectInstanceCreated(SomeService);
});
it('should allow to create private components from imported NgModule summaries', () => {
resetTestEnvironmentWithSummaries(summaries);
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
it('should allow to create private components from imported NgModule summaries', () => {
resetTestEnvironmentWithSummaries(summaries);
TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
.createComponent(SomePrivateComponent);
expectInstanceCreated(SomePrivateComponent);
});
TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
.createComponent(SomePrivateComponent);
expectInstanceCreated(SomePrivateComponent);
});
it('should throw when trying to mock a type with a summary', () => {
resetTestEnvironmentWithSummaries(summaries);
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
it('should throw when trying to mock a type with a summary', () => {
resetTestEnvironmentWithSummaries(summaries);
TestBed.resetTestingModule();
expect(() => TestBed.overrideComponent(SomePrivateComponent, {add: {}}).compileComponents())
.toThrowError(
'SomePrivateComponent was AOT compiled, so its metadata cannot be changed.');
TestBed.resetTestingModule();
expect(() => TestBed.overrideDirective(SomeDirective, {add: {}}).compileComponents())
.toThrowError('SomeDirective was AOT compiled, so its metadata cannot be changed.');
TestBed.resetTestingModule();
expect(() => TestBed.overridePipe(SomePipe, {add: {name: 'test'}}).compileComponents())
.toThrowError('SomePipe was AOT compiled, so its metadata cannot be changed.');
TestBed.resetTestingModule();
expect(() => TestBed.overrideModule(SomeModule, {add: {}}).compileComponents())
.toThrowError('SomeModule was AOT compiled, so its metadata cannot be changed.');
});
TestBed.resetTestingModule();
expect(
() => TestBed.overrideComponent(SomePrivateComponent, {add: {}}).compileComponents())
.toThrowError(
'SomePrivateComponent was AOT compiled, so its metadata cannot be changed.');
TestBed.resetTestingModule();
expect(() => TestBed.overrideDirective(SomeDirective, {add: {}}).compileComponents())
.toThrowError('SomeDirective was AOT compiled, so its metadata cannot be changed.');
TestBed.resetTestingModule();
expect(() => TestBed.overridePipe(SomePipe, {add: {name: 'test'}}).compileComponents())
.toThrowError('SomePipe was AOT compiled, so its metadata cannot be changed.');
TestBed.resetTestingModule();
expect(() => TestBed.overrideModule(SomeModule, {add: {}}).compileComponents())
.toThrowError('SomeModule was AOT compiled, so its metadata cannot be changed.');
});
it('should return stack trace and component data on resetTestingModule when error is thrown',
() => {
resetTestEnvironmentWithSummaries();
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
it('should return stack trace and component data on resetTestingModule when error is thrown',
() => {
resetTestEnvironmentWithSummaries();
const fixture = TestBed.configureTestingModule({declarations: [TestCompErrorOnDestroy]})
.createComponent<TestCompErrorOnDestroy>(TestCompErrorOnDestroy);
const fixture =
TestBed.configureTestingModule({declarations: [TestCompErrorOnDestroy]})
.createComponent<TestCompErrorOnDestroy>(TestCompErrorOnDestroy);
const expectedError = 'Error from ngOnDestroy';
const expectedError = 'Error from ngOnDestroy';
const component: TestCompErrorOnDestroy = fixture.componentInstance;
const component: TestCompErrorOnDestroy = fixture.componentInstance;
spyOn(console, 'error');
spyOn(component, 'ngOnDestroy').and.throwError(expectedError);
spyOn(console, 'error');
spyOn(component, 'ngOnDestroy').and.throwError(expectedError);
const expectedObject = {
stacktrace: new Error(expectedError),
component,
};
const expectedObject = {
stacktrace: new Error(expectedError),
component,
};
TestBed.resetTestingModule();
TestBed.resetTestingModule();
expect(console.error)
.toHaveBeenCalledWith('Error during cleanup of component', expectedObject);
});
expect(console.error)
.toHaveBeenCalledWith('Error during cleanup of component', expectedObject);
});
it('should allow to add summaries via configureTestingModule', () => {
resetTestEnvironmentWithSummaries();
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
it('should allow to add summaries via configureTestingModule', () => {
resetTestEnvironmentWithSummaries();
@Component({template: '<div someDir></div>'})
class TestComp {
}
@Component({template: '<div someDir></div>'})
class TestComp {
}
TestBed
.configureTestingModule({
providers: [SomeDep],
declarations: [TestComp, SomeDirective],
aotSummaries: summaries
})
.createComponent(TestComp);
expectInstanceCreated(SomeDirective);
});
TestBed
.configureTestingModule({
providers: [SomeDep],
declarations: [TestComp, SomeDirective],
aotSummaries: summaries
})
.createComponent(TestComp);
expectInstanceCreated(SomeDirective);
});
it('should allow to override a provider', () => {
resetTestEnvironmentWithSummaries(summaries);
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
it('should allow to override a provider', () => {
resetTestEnvironmentWithSummaries(summaries);
const overwrittenValue = {};
const overwrittenValue = {};
const fixture =
TestBed.overrideProvider(SomeDep, {useFactory: () => overwrittenValue, deps: []})
.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
.createComponent<SomePublicComponent>(SomePublicComponent);
const fixture =
TestBed.overrideProvider(SomeDep, {useFactory: () => overwrittenValue, deps: []})
.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
.createComponent<SomePublicComponent>(SomePublicComponent);
expect(fixture.componentInstance.dep).toBe(overwrittenValue);
});
expect(fixture.componentInstance.dep).toBe(overwrittenValue);
});
it('should allow to override a template', () => {
resetTestEnvironmentWithSummaries(summaries);
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
it('should allow to override a template', () => {
resetTestEnvironmentWithSummaries(summaries);
TestBed.overrideTemplateUsingTestingModule(SomePublicComponent, 'overwritten');
TestBed.overrideTemplateUsingTestingModule(SomePublicComponent, 'overwritten');
const fixture = TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
.createComponent(SomePublicComponent);
expectInstanceCreated(SomePublicComponent);
const fixture =
TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
.createComponent(SomePublicComponent);
expectInstanceCreated(SomePublicComponent);
expect(fixture.nativeElement).toHaveText('overwritten');
});
expect(fixture.nativeElement).toHaveText('overwritten');
});
});
}
File diff suppressed because it is too large Load Diff
@@ -14,7 +14,7 @@ import {fixmeIvy} from '@angular/private/testing';
{
if (ivyEnabled) {
fixmeIvy('unknown') && describe('ivy', () => { declareTests(); });
describe('ivy', () => { declareTests(); });
} else {
describe('jit', () => { declareTests({useJit: true}); });
describe('no jit', () => { declareTests({useJit: false}); });
@@ -52,7 +52,7 @@ function declareTests(config?: {useJit: boolean}) {
afterEach(() => { getDOM().log = originalLog; });
describe('events', () => {
it('should disallow binding to attr.on*', () => {
fixmeIvy('unknown') && it('should disallow binding to attr.on*', () => {
const template = `<div [attr.onclick]="ctxProp"></div>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
@@ -61,7 +61,7 @@ function declareTests(config?: {useJit: boolean}) {
/Binding to event attribute 'onclick' is disallowed for security reasons, please use \(click\)=.../);
});
it('should disallow binding to on* with NO_ERRORS_SCHEMA', () => {
fixmeIvy('unknown') && it('should disallow binding to on* with NO_ERRORS_SCHEMA', () => {
const template = `<div [onclick]="ctxProp"></div>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({
schemas: [NO_ERRORS_SCHEMA]
@@ -72,29 +72,30 @@ function declareTests(config?: {useJit: boolean}) {
/Binding to event property 'onclick' is disallowed for security reasons, please use \(click\)=.../);
});
it('should disallow binding to on* unless it is consumed by a directive', () => {
const template = `<div [onPrefixedProp]="ctxProp" [onclick]="ctxProp"></div>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({
schemas: [NO_ERRORS_SCHEMA]
});
fixmeIvy('unknown') &&
it('should disallow binding to on* unless it is consumed by a directive', () => {
const template = `<div [onPrefixedProp]="ctxProp" [onclick]="ctxProp"></div>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({
schemas: [NO_ERRORS_SCHEMA]
});
// should not throw for inputs starting with "on"
let cmp: ComponentFixture<SecuredComponent> = undefined !;
expect(() => cmp = TestBed.createComponent(SecuredComponent)).not.toThrow();
// should not throw for inputs starting with "on"
let cmp: ComponentFixture<SecuredComponent> = undefined !;
expect(() => cmp = TestBed.createComponent(SecuredComponent)).not.toThrow();
// must bind to the directive not to the property of the div
const value = cmp.componentInstance.ctxProp = {};
cmp.detectChanges();
const div = cmp.debugElement.children[0];
expect(div.injector.get(OnPrefixDir).onclick).toBe(value);
expect(getDOM().getProperty(div.nativeElement, 'onclick')).not.toBe(value);
expect(getDOM().hasAttribute(div.nativeElement, 'onclick')).toEqual(false);
});
// must bind to the directive not to the property of the div
const value = cmp.componentInstance.ctxProp = {};
cmp.detectChanges();
const div = cmp.debugElement.children[0];
expect(div.injector.get(OnPrefixDir).onclick).toBe(value);
expect(getDOM().getProperty(div.nativeElement, 'onclick')).not.toBe(value);
expect(getDOM().hasAttribute(div.nativeElement, 'onclick')).toEqual(false);
});
});
describe('safe HTML values', function() {
it('should not escape values marked as trusted', () => {
fixmeIvy('unknown') && it('should not escape values marked as trusted', () => {
const template = `<a [href]="ctxProp">Link Title</a>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent);
@@ -108,7 +109,7 @@ function declareTests(config?: {useJit: boolean}) {
expect(getDOM().getProperty(e, 'href')).toEqual('javascript:alert(1)');
});
it('should error when using the wrong trusted value', () => {
fixmeIvy('unknown') && it('should error when using the wrong trusted value', () => {
const template = `<a [href]="ctxProp">Link Title</a>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent);
@@ -120,7 +121,7 @@ function declareTests(config?: {useJit: boolean}) {
expect(() => fixture.detectChanges()).toThrowError(/Required a safe URL, got a Script/);
});
it('should warn when using in string interpolation', () => {
fixmeIvy('unknown') && it('should warn when using in string interpolation', () => {
const template = `<a href="/foo/{{ctxProp}}">Link Title</a>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent);
@@ -153,7 +154,7 @@ function declareTests(config?: {useJit: boolean}) {
expect(value).toEqual('unsafe:javascript:alert(1)');
}
it('should escape unsafe properties', () => {
fixmeIvy('unknown') && it('should escape unsafe properties', () => {
const template = `<a [href]="ctxProp">Link Title</a>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent);
@@ -161,7 +162,7 @@ function declareTests(config?: {useJit: boolean}) {
checkEscapeOfHrefProperty(fixture, false);
});
it('should escape unsafe attributes', () => {
fixmeIvy('unknown') && it('should escape unsafe attributes', () => {
const template = `<a [attr.href]="ctxProp">Link Title</a>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent);
@@ -169,39 +170,41 @@ function declareTests(config?: {useJit: boolean}) {
checkEscapeOfHrefProperty(fixture, true);
});
it('should escape unsafe properties if they are used in host bindings', () => {
@Directive({selector: '[dirHref]'})
class HrefDirective {
// TODO(issue/24571): remove '!'.
@HostBinding('href') @Input()
dirHref !: string;
}
fixmeIvy('unknown') &&
it('should escape unsafe properties if they are used in host bindings', () => {
@Directive({selector: '[dirHref]'})
class HrefDirective {
// TODO(issue/24571): remove '!'.
@HostBinding('href') @Input()
dirHref !: string;
}
const template = `<a [dirHref]="ctxProp">Link Title</a>`;
TestBed.configureTestingModule({declarations: [HrefDirective]});
TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent);
const template = `<a [dirHref]="ctxProp">Link Title</a>`;
TestBed.configureTestingModule({declarations: [HrefDirective]});
TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent);
checkEscapeOfHrefProperty(fixture, false);
});
checkEscapeOfHrefProperty(fixture, false);
});
it('should escape unsafe attributes if they are used in host bindings', () => {
@Directive({selector: '[dirHref]'})
class HrefDirective {
// TODO(issue/24571): remove '!'.
@HostBinding('attr.href') @Input()
dirHref !: string;
}
fixmeIvy('unknown') &&
it('should escape unsafe attributes if they are used in host bindings', () => {
@Directive({selector: '[dirHref]'})
class HrefDirective {
// TODO(issue/24571): remove '!'.
@HostBinding('attr.href') @Input()
dirHref !: string;
}
const template = `<a [dirHref]="ctxProp">Link Title</a>`;
TestBed.configureTestingModule({declarations: [HrefDirective]});
TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent);
const template = `<a [dirHref]="ctxProp">Link Title</a>`;
TestBed.configureTestingModule({declarations: [HrefDirective]});
TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent);
checkEscapeOfHrefProperty(fixture, true);
});
checkEscapeOfHrefProperty(fixture, true);
});
it('should escape unsafe style values', () => {
fixmeIvy('unknown') && it('should escape unsafe style values', () => {
const template = `<div [style.background]="ctxProp">Text</div>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent);
@@ -221,7 +224,7 @@ function declareTests(config?: {useJit: boolean}) {
expect(getDOM().getStyle(e, 'background')).not.toContain('javascript');
});
it('should escape unsafe SVG attributes', () => {
fixmeIvy('unknown') && it('should escape unsafe SVG attributes', () => {
const template = `<svg:circle [xlink:href]="ctxProp">Text</svg:circle>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
@@ -229,7 +232,7 @@ function declareTests(config?: {useJit: boolean}) {
.toThrowError(/Can't bind to 'xlink:href'/);
});
it('should escape unsafe HTML values', () => {
fixmeIvy('unknown') && it('should escape unsafe HTML values', () => {
const template = `<div [innerHTML]="ctxProp">Text</div>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
const fixture = TestBed.createComponent(SecuredComponent);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+44 -41
View File
@@ -114,10 +114,10 @@ import {fixmeIvy} from '@angular/private/testing';
expect(debugCtx.nodeIndex).toBe(1);
});
fixmeIvy('unknown') && describe('deps', () => {
describe('deps', () => {
class Dep {}
it('should inject deps from the same element', () => {
fixmeIvy('unknown') && it('should inject deps from the same element', () => {
createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 2, 'span'),
directiveDef(1, NodeFlags.None, null, 0, Dep, []),
@@ -127,7 +127,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep instanceof Dep).toBeTruthy();
});
it('should inject deps from a parent element', () => {
fixmeIvy('unknown') && it('should inject deps from a parent element', () => {
createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 3, 'span'),
directiveDef(1, NodeFlags.None, null, 0, Dep, []),
@@ -138,7 +138,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep instanceof Dep).toBeTruthy();
});
it('should not inject deps from sibling root elements', () => {
fixmeIvy('unknown') && it('should not inject deps from sibling root elements', () => {
const rootElNodes = [
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef(1, NodeFlags.None, null, 0, Dep, []),
@@ -167,7 +167,7 @@ import {fixmeIvy} from '@angular/private/testing';
' NullInjectorError: No provider for Dep!');
});
it('should inject from a parent element in a parent view', () => {
fixmeIvy('unknown') && it('should inject from a parent element in a parent view', () => {
createAndGetRootNodes(compViewDef([
elementDef(
0, NodeFlags.None, null, null, 1, 'div', null, null, null, null,
@@ -181,7 +181,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep instanceof Dep).toBeTruthy();
});
it('should throw for missing dependencies', () => {
fixmeIvy('unknown') && it('should throw for missing dependencies', () => {
expect(() => createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef(1, NodeFlags.None, null, 0, SomeService, ['nonExistingDep'])
@@ -192,7 +192,7 @@ import {fixmeIvy} from '@angular/private/testing';
' NullInjectorError: No provider for nonExistingDep!');
});
it('should use null for optional missing dependencies', () => {
fixmeIvy('unknown') && it('should use null for optional missing dependencies', () => {
createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef(
@@ -202,7 +202,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep).toBe(null);
});
it('should skip the current element when using SkipSelf', () => {
fixmeIvy('unknown') && it('should skip the current element when using SkipSelf', () => {
createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 4, 'span'),
providerDef(NodeFlags.TypeValueProvider, null, 'someToken', 'someParentValue', []),
@@ -214,18 +214,19 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep).toBe('someParentValue');
});
it('should ask the root injector',
withModule({providers: [{provide: 'rootDep', useValue: 'rootValue'}]}, () => {
createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef(1, NodeFlags.None, null, 0, SomeService, ['rootDep'])
]));
fixmeIvy('unknown') &&
it('should ask the root injector',
withModule({providers: [{provide: 'rootDep', useValue: 'rootValue'}]}, () => {
createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef(1, NodeFlags.None, null, 0, SomeService, ['rootDep'])
]));
expect(instance.dep).toBe('rootValue');
}));
expect(instance.dep).toBe('rootValue');
}));
describe('builtin tokens', () => {
it('should inject ViewContainerRef', () => {
fixmeIvy('unknown') && it('should inject ViewContainerRef', () => {
createAndGetRootNodes(compViewDef([
anchorDef(NodeFlags.EmbeddedViews, null, null, 1),
directiveDef(1, NodeFlags.None, null, 0, SomeService, [ViewContainerRef]),
@@ -234,7 +235,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep.createEmbeddedView).toBeTruthy();
});
it('should inject TemplateRef', () => {
fixmeIvy('unknown') && it('should inject TemplateRef', () => {
createAndGetRootNodes(compViewDef([
anchorDef(NodeFlags.None, null, null, 1, null, compViewDefFactory([anchorDef(
NodeFlags.None, null, null, 0)])),
@@ -244,7 +245,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep.createEmbeddedView).toBeTruthy();
});
it('should inject ElementRef', () => {
fixmeIvy('unknown') && it('should inject ElementRef', () => {
const {view} = createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef(1, NodeFlags.None, null, 0, SomeService, [ElementRef]),
@@ -253,7 +254,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep.nativeElement).toBe(asElementData(view, 0).renderElement);
});
it('should inject Injector', () => {
fixmeIvy('unknown') && it('should inject Injector', () => {
const {view} = createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef(1, NodeFlags.None, null, 0, SomeService, [Injector]),
@@ -262,30 +263,32 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep.get(SomeService)).toBe(instance);
});
it('should inject ChangeDetectorRef for non component providers', () => {
const {view} = createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef(1, NodeFlags.None, null, 0, SomeService, [ChangeDetectorRef])
]));
fixmeIvy('unknown') &&
it('should inject ChangeDetectorRef for non component providers', () => {
const {view} = createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef(1, NodeFlags.None, null, 0, SomeService, [ChangeDetectorRef])
]));
expect(instance.dep._view).toBe(view);
});
expect(instance.dep._view).toBe(view);
});
it('should inject ChangeDetectorRef for component providers', () => {
const {view, rootNodes} = createAndGetRootNodes(compViewDef([
elementDef(
0, NodeFlags.None, null, null, 1, 'div', null, null, null, null,
() => compViewDef([
elementDef(0, NodeFlags.None, null, null, 0, 'span'),
])),
directiveDef(1, NodeFlags.Component, null, 0, SomeService, [ChangeDetectorRef]),
]));
fixmeIvy('unknown') &&
it('should inject ChangeDetectorRef for component providers', () => {
const {view, rootNodes} = createAndGetRootNodes(compViewDef([
elementDef(
0, NodeFlags.None, null, null, 1, 'div', null, null, null, null,
() => compViewDef([
elementDef(0, NodeFlags.None, null, null, 0, 'span'),
])),
directiveDef(1, NodeFlags.Component, null, 0, SomeService, [ChangeDetectorRef]),
]));
const compView = asElementData(view, 0).componentView;
expect(instance.dep._view).toBe(compView);
});
const compView = asElementData(view, 0).componentView;
expect(instance.dep._view).toBe(compView);
});
it('should inject RendererV1', () => {
fixmeIvy('unknown') && it('should inject RendererV1', () => {
createAndGetRootNodes(compViewDef([
elementDef(
0, NodeFlags.None, null, null, 1, 'span', null, null, null, null,
@@ -296,7 +299,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep.createElement).toBeTruthy();
});
it('should inject Renderer2', () => {
fixmeIvy('unknown') && it('should inject Renderer2', () => {
createAndGetRootNodes(compViewDef([
elementDef(
0, NodeFlags.None, null, null, 1, 'span', null, null, null, null,