style(lint): re-format modules/@angular
This commit is contained in:
@ -1,36 +1,14 @@
|
||||
import {
|
||||
ddescribe,
|
||||
describe,
|
||||
it,
|
||||
iit,
|
||||
xit,
|
||||
expect,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
inject,
|
||||
beforeEachProviders
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {
|
||||
fakeAsync,
|
||||
flushMicrotasks,
|
||||
Log,
|
||||
tick,
|
||||
} from '@angular/core/testing';
|
||||
import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {fakeAsync, flushMicrotasks, Log, tick,} from '@angular/core/testing';
|
||||
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
|
||||
|
||||
import {
|
||||
isBlank,
|
||||
NumberWrapper,
|
||||
} from '../../src/facade/lang';
|
||||
import {isBlank, NumberWrapper,} from '../../src/facade/lang';
|
||||
import {BaseException} from '../../src/facade/exceptions';
|
||||
import {StringMapWrapper} from '../../src/facade/collection';
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
|
||||
import {
|
||||
PipeTransform,
|
||||
ChangeDetectionStrategy,
|
||||
WrappedValue,
|
||||
} from '@angular/core/src/change_detection/change_detection';
|
||||
import {PipeTransform, ChangeDetectionStrategy, WrappedValue,} from '@angular/core/src/change_detection/change_detection';
|
||||
|
||||
import {OnDestroy} from '@angular/core/src/metadata/lifecycle_hooks';
|
||||
|
||||
@ -38,31 +16,7 @@ import {IS_DART, Type} from '../../src/facade/lang';
|
||||
import {EventEmitter, ObservableWrapper} from '../../src/facade/async';
|
||||
|
||||
|
||||
import {
|
||||
Component,
|
||||
DebugElement,
|
||||
Directive,
|
||||
TemplateRef,
|
||||
ChangeDetectorRef,
|
||||
ViewContainerRef,
|
||||
Input,
|
||||
Output,
|
||||
forwardRef,
|
||||
ViewMetadata,
|
||||
Pipe,
|
||||
RootRenderer,
|
||||
Renderer,
|
||||
RenderComponentType,
|
||||
Injectable,
|
||||
provide,
|
||||
OnInit,
|
||||
DoCheck,
|
||||
OnChanges,
|
||||
AfterContentInit,
|
||||
AfterContentChecked,
|
||||
AfterViewInit,
|
||||
AfterViewChecked
|
||||
} from '@angular/core';
|
||||
import {Component, DebugElement, Directive, TemplateRef, ChangeDetectorRef, ViewContainerRef, Input, Output, forwardRef, ViewMetadata, Pipe, RootRenderer, Renderer, RenderComponentType, Injectable, provide, OnInit, DoCheck, OnChanges, AfterContentInit, AfterContentChecked, AfterViewInit, AfterViewChecked} from '@angular/core';
|
||||
import {NgFor} from '@angular/common';
|
||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||
import {AsyncPipe} from '@angular/common';
|
||||
@ -79,15 +33,16 @@ export function main() {
|
||||
var renderLog: RenderLog;
|
||||
var directiveLog: DirectiveLog;
|
||||
|
||||
function createCompFixture(template: string, compType: Type = TestComponent,
|
||||
_tcb: TestComponentBuilder = null): ComponentFixture<any> {
|
||||
function createCompFixture(
|
||||
template: string, compType: Type = TestComponent,
|
||||
_tcb: TestComponentBuilder = null): ComponentFixture<any> {
|
||||
if (isBlank(_tcb)) {
|
||||
_tcb = tcb;
|
||||
}
|
||||
return _tcb.overrideView(
|
||||
compType,
|
||||
new ViewMetadata(
|
||||
{template: template, directives: ALL_DIRECTIVES, pipes: ALL_PIPES}))
|
||||
return _tcb
|
||||
.overrideView(
|
||||
compType,
|
||||
new ViewMetadata({template: template, directives: ALL_DIRECTIVES, pipes: ALL_PIPES}))
|
||||
.createFakeAsync(compType);
|
||||
}
|
||||
|
||||
@ -96,14 +51,14 @@ export function main() {
|
||||
return nodes.map(node => node.inject(dirType));
|
||||
}
|
||||
|
||||
function _bindSimpleProp(bindAttr: string,
|
||||
compType: Type = TestComponent): ComponentFixture<any> {
|
||||
function _bindSimpleProp(
|
||||
bindAttr: string, compType: Type = TestComponent): ComponentFixture<any> {
|
||||
var template = `<div ${bindAttr}></div>`;
|
||||
return createCompFixture(template, compType);
|
||||
}
|
||||
|
||||
function _bindSimpleValue(expression: any,
|
||||
compType: Type = TestComponent): ComponentFixture<any> {
|
||||
function _bindSimpleValue(
|
||||
expression: any, compType: Type = TestComponent): ComponentFixture<any> {
|
||||
return _bindSimpleProp(`[someProp]='${expression}'`, compType);
|
||||
}
|
||||
|
||||
@ -117,21 +72,22 @@ export function main() {
|
||||
// On CJS fakeAsync is not supported...
|
||||
if (!getDOM().supportsDOMEvents()) return;
|
||||
|
||||
beforeEachProviders(() => [
|
||||
RenderLog,
|
||||
DirectiveLog,
|
||||
{provide: RootRenderer, useClass: LoggingRootRenderer},
|
||||
TEST_PROVIDERS,
|
||||
beforeEachProviders(
|
||||
() =>
|
||||
[RenderLog, DirectiveLog, {provide: RootRenderer, useClass: LoggingRootRenderer},
|
||||
TEST_PROVIDERS,
|
||||
]);
|
||||
|
||||
beforeEach(inject([TestComponentBuilder, ElementSchemaRegistry, RenderLog, DirectiveLog],
|
||||
(_tcb: TestComponentBuilder, _elSchema: MockSchemaRegistry, _renderLog: RenderLog, _directiveLog: DirectiveLog) => {
|
||||
tcb = _tcb;
|
||||
elSchema = _elSchema;
|
||||
renderLog = _renderLog;
|
||||
directiveLog = _directiveLog;
|
||||
elSchema.existingProperties['someProp'] = true;
|
||||
}));
|
||||
beforeEach(inject(
|
||||
[TestComponentBuilder, ElementSchemaRegistry, RenderLog, DirectiveLog],
|
||||
(_tcb: TestComponentBuilder, _elSchema: MockSchemaRegistry, _renderLog: RenderLog,
|
||||
_directiveLog: DirectiveLog) => {
|
||||
tcb = _tcb;
|
||||
elSchema = _elSchema;
|
||||
renderLog = _renderLog;
|
||||
directiveLog = _directiveLog;
|
||||
elSchema.existingProperties['someProp'] = true;
|
||||
}));
|
||||
|
||||
describe('expressions', () => {
|
||||
|
||||
@ -530,11 +486,13 @@ export function main() {
|
||||
// change from some value -> some other value
|
||||
ctx.componentInstance.name = 'bart';
|
||||
ctx.detectChanges(false);
|
||||
expect(renderLog.loggedValues)
|
||||
.toEqual(['null state:0', 'bob state:1', 'bart state:2']);
|
||||
expect(renderLog.loggedValues).toEqual([
|
||||
'null state:0', 'bob state:1', 'bart state:2'
|
||||
]);
|
||||
ctx.detectChanges(false);
|
||||
expect(renderLog.loggedValues)
|
||||
.toEqual(['null state:0', 'bob state:1', 'bart state:2']);
|
||||
expect(renderLog.loggedValues).toEqual([
|
||||
'null state:0', 'bob state:1', 'bart state:2'
|
||||
]);
|
||||
|
||||
}));
|
||||
|
||||
@ -548,15 +506,18 @@ export function main() {
|
||||
ctx.componentInstance.age = 10;
|
||||
ctx.componentInstance.address = new Address('mtv');
|
||||
ctx.detectChanges(false);
|
||||
expect(renderLog.loggedValues)
|
||||
.toEqual(['mtv state:0', 'mtv state:1', 'a state:2', '10 state:3']);
|
||||
expect(renderLog.loggedValues).toEqual([
|
||||
'mtv state:0', 'mtv state:1', 'a state:2', '10 state:3'
|
||||
]);
|
||||
ctx.detectChanges(false);
|
||||
expect(renderLog.loggedValues)
|
||||
.toEqual(['mtv state:0', 'mtv state:1', 'a state:2', '10 state:3']);
|
||||
expect(renderLog.loggedValues).toEqual([
|
||||
'mtv state:0', 'mtv state:1', 'a state:2', '10 state:3'
|
||||
]);
|
||||
ctx.componentInstance.age = 11;
|
||||
ctx.detectChanges(false);
|
||||
expect(renderLog.loggedValues)
|
||||
.toEqual(['mtv state:0', 'mtv state:1', 'a state:2', '10 state:3', '11 state:4']);
|
||||
expect(renderLog.loggedValues).toEqual([
|
||||
'mtv state:0', 'mtv state:1', 'a state:2', '10 state:3', '11 state:4'
|
||||
]);
|
||||
}));
|
||||
|
||||
it('should call impure pipes on each change detection run', fakeAsync(() => {
|
||||
@ -599,7 +560,7 @@ export function main() {
|
||||
|
||||
it('should throw when trying to assign to a local', fakeAsync(() => {
|
||||
expect(() => {_bindSimpleProp('(event)="$event=1"')})
|
||||
.toThrowError(new RegExp("Cannot assign to a reference or variable!"));
|
||||
.toThrowError(new RegExp('Cannot assign to a reference or variable!'));
|
||||
}));
|
||||
|
||||
it('should support short-circuiting', fakeAsync(() => {
|
||||
@ -625,10 +586,9 @@ export function main() {
|
||||
|
||||
describe('reading directives', () => {
|
||||
it('should read directive properties', fakeAsync(() => {
|
||||
var ctx =
|
||||
createCompFixture(
|
||||
'<div testDirective [a]="42" ref-dir="testDirective" [someProp]="dir.a"></div>')
|
||||
ctx.detectChanges(false);
|
||||
var ctx = createCompFixture(
|
||||
'<div testDirective [a]="42" ref-dir="testDirective" [someProp]="dir.a"></div>')
|
||||
ctx.detectChanges(false);
|
||||
expect(renderLog.loggedValues).toEqual([42]);
|
||||
}));
|
||||
});
|
||||
@ -661,8 +621,9 @@ export function main() {
|
||||
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngOnInit', 'ngOnChanges']))
|
||||
.toEqual(['dir.ngOnChanges', 'dir.ngOnInit']);
|
||||
expect(directiveLog.filter(['ngOnInit', 'ngOnChanges'])).toEqual([
|
||||
'dir.ngOnChanges', 'dir.ngOnInit'
|
||||
]);
|
||||
directiveLog.clear();
|
||||
|
||||
ctx.detectChanges(false);
|
||||
@ -710,7 +671,7 @@ export function main() {
|
||||
try {
|
||||
ctx.detectChanges(false);
|
||||
} catch (e) {
|
||||
throw new BaseException("Second detectChanges() should not have run detection.");
|
||||
throw new BaseException('Second detectChanges() should not have run detection.');
|
||||
}
|
||||
expect(directiveLog.filter(['ngOnInit'])).toEqual([]);
|
||||
}));
|
||||
@ -721,8 +682,9 @@ export function main() {
|
||||
var ctx = createCompFixture('<div testDirective="dir"></div>');
|
||||
|
||||
ctx.detectChanges(false);
|
||||
expect(directiveLog.filter(['ngDoCheck', 'ngOnInit']))
|
||||
.toEqual(['dir.ngOnInit', 'dir.ngDoCheck']);
|
||||
expect(directiveLog.filter(['ngDoCheck', 'ngOnInit'])).toEqual([
|
||||
'dir.ngOnInit', 'dir.ngDoCheck'
|
||||
]);
|
||||
}));
|
||||
|
||||
it('should be called on every detectChanges run, except for checkNoChanges',
|
||||
@ -755,15 +717,10 @@ export function main() {
|
||||
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngDoCheck', 'ngAfterContentInit']))
|
||||
.toEqual([
|
||||
'parent.ngDoCheck',
|
||||
'contentChild.ngDoCheck',
|
||||
'contentChild.ngAfterContentInit',
|
||||
'parent.ngAfterContentInit',
|
||||
'viewChild.ngDoCheck',
|
||||
'viewChild.ngAfterContentInit'
|
||||
]);
|
||||
expect(directiveLog.filter(['ngDoCheck', 'ngAfterContentInit'])).toEqual([
|
||||
'parent.ngDoCheck', 'contentChild.ngDoCheck', 'contentChild.ngAfterContentInit',
|
||||
'parent.ngAfterContentInit', 'viewChild.ngDoCheck', 'viewChild.ngAfterContentInit'
|
||||
]);
|
||||
}));
|
||||
|
||||
it('should only be called only once', fakeAsync(() => {
|
||||
@ -771,8 +728,9 @@ export function main() {
|
||||
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngAfterContentInit']))
|
||||
.toEqual(['dir.ngAfterContentInit']);
|
||||
expect(directiveLog.filter(['ngAfterContentInit'])).toEqual([
|
||||
'dir.ngAfterContentInit'
|
||||
]);
|
||||
|
||||
// reset directives
|
||||
directiveLog.clear();
|
||||
@ -801,8 +759,9 @@ export function main() {
|
||||
}
|
||||
expect(errored).toBe(true);
|
||||
|
||||
expect(directiveLog.filter(['ngAfterContentInit']))
|
||||
.toEqual(['dir.ngAfterContentInit']);
|
||||
expect(directiveLog.filter(['ngAfterContentInit'])).toEqual([
|
||||
'dir.ngAfterContentInit'
|
||||
]);
|
||||
directiveLog.clear();
|
||||
|
||||
// Second change detection also fails, but this time ngAfterContentInit should not be
|
||||
@ -810,7 +769,7 @@ export function main() {
|
||||
try {
|
||||
ctx.detectChanges(false);
|
||||
} catch (e) {
|
||||
throw new BaseException("Second detectChanges() should not have run detection.");
|
||||
throw new BaseException('Second detectChanges() should not have run detection.');
|
||||
}
|
||||
expect(directiveLog.filter(['ngAfterContentInit'])).toEqual([]);
|
||||
}));
|
||||
@ -823,15 +782,11 @@ export function main() {
|
||||
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngDoCheck', 'ngAfterContentChecked']))
|
||||
.toEqual([
|
||||
'parent.ngDoCheck',
|
||||
'contentChild.ngDoCheck',
|
||||
'contentChild.ngAfterContentChecked',
|
||||
'parent.ngAfterContentChecked',
|
||||
'viewChild.ngDoCheck',
|
||||
'viewChild.ngAfterContentChecked'
|
||||
]);
|
||||
expect(directiveLog.filter(['ngDoCheck', 'ngAfterContentChecked'])).toEqual([
|
||||
'parent.ngDoCheck', 'contentChild.ngDoCheck', 'contentChild.ngAfterContentChecked',
|
||||
'parent.ngAfterContentChecked', 'viewChild.ngDoCheck',
|
||||
'viewChild.ngAfterContentChecked'
|
||||
]);
|
||||
}));
|
||||
|
||||
it('should be called on every detectChanges run, except for checkNoChanges',
|
||||
@ -840,8 +795,9 @@ export function main() {
|
||||
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngAfterContentChecked']))
|
||||
.toEqual(['dir.ngAfterContentChecked']);
|
||||
expect(directiveLog.filter(['ngAfterContentChecked'])).toEqual([
|
||||
'dir.ngAfterContentChecked'
|
||||
]);
|
||||
|
||||
// reset directives
|
||||
directiveLog.clear();
|
||||
@ -854,8 +810,9 @@ export function main() {
|
||||
// re-verify that changes are still detected
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngAfterContentChecked']))
|
||||
.toEqual(['dir.ngAfterContentChecked']);
|
||||
expect(directiveLog.filter(['ngAfterContentChecked'])).toEqual([
|
||||
'dir.ngAfterContentChecked'
|
||||
]);
|
||||
}));
|
||||
|
||||
it('should be called in reverse order so the child is always notified before the parent',
|
||||
@ -865,8 +822,9 @@ export function main() {
|
||||
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngAfterContentChecked']))
|
||||
.toEqual(['child.ngAfterContentChecked', 'parent.ngAfterContentChecked']);
|
||||
expect(directiveLog.filter(['ngAfterContentChecked'])).toEqual([
|
||||
'child.ngAfterContentChecked', 'parent.ngAfterContentChecked'
|
||||
]);
|
||||
}));
|
||||
});
|
||||
|
||||
@ -877,15 +835,10 @@ export function main() {
|
||||
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngDoCheck', 'ngAfterViewInit']))
|
||||
.toEqual([
|
||||
'parent.ngDoCheck',
|
||||
'contentChild.ngDoCheck',
|
||||
'contentChild.ngAfterViewInit',
|
||||
'viewChild.ngDoCheck',
|
||||
'viewChild.ngAfterViewInit',
|
||||
'parent.ngAfterViewInit'
|
||||
]);
|
||||
expect(directiveLog.filter(['ngDoCheck', 'ngAfterViewInit'])).toEqual([
|
||||
'parent.ngDoCheck', 'contentChild.ngDoCheck', 'contentChild.ngAfterViewInit',
|
||||
'viewChild.ngDoCheck', 'viewChild.ngAfterViewInit', 'parent.ngAfterViewInit'
|
||||
]);
|
||||
}));
|
||||
|
||||
it('should only be called only once', fakeAsync(() => {
|
||||
@ -930,7 +883,7 @@ export function main() {
|
||||
try {
|
||||
ctx.detectChanges(false);
|
||||
} catch (e) {
|
||||
throw new BaseException("Second detectChanges() should not have run detection.");
|
||||
throw new BaseException('Second detectChanges() should not have run detection.');
|
||||
}
|
||||
expect(directiveLog.filter(['ngAfterViewInit'])).toEqual([]);
|
||||
}));
|
||||
@ -942,15 +895,10 @@ export function main() {
|
||||
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngDoCheck', 'ngAfterViewChecked']))
|
||||
.toEqual([
|
||||
'parent.ngDoCheck',
|
||||
'contentChild.ngDoCheck',
|
||||
'contentChild.ngAfterViewChecked',
|
||||
'viewChild.ngDoCheck',
|
||||
'viewChild.ngAfterViewChecked',
|
||||
'parent.ngAfterViewChecked'
|
||||
]);
|
||||
expect(directiveLog.filter(['ngDoCheck', 'ngAfterViewChecked'])).toEqual([
|
||||
'parent.ngDoCheck', 'contentChild.ngDoCheck', 'contentChild.ngAfterViewChecked',
|
||||
'viewChild.ngDoCheck', 'viewChild.ngAfterViewChecked', 'parent.ngAfterViewChecked'
|
||||
]);
|
||||
}));
|
||||
|
||||
it('should be called on every detectChanges run, except for checkNoChanges',
|
||||
@ -959,8 +907,9 @@ export function main() {
|
||||
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngAfterViewChecked']))
|
||||
.toEqual(['dir.ngAfterViewChecked']);
|
||||
expect(directiveLog.filter(['ngAfterViewChecked'])).toEqual([
|
||||
'dir.ngAfterViewChecked'
|
||||
]);
|
||||
|
||||
// reset directives
|
||||
directiveLog.clear();
|
||||
@ -973,8 +922,9 @@ export function main() {
|
||||
// re-verify that changes are still detected
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngAfterViewChecked']))
|
||||
.toEqual(['dir.ngAfterViewChecked']);
|
||||
expect(directiveLog.filter(['ngAfterViewChecked'])).toEqual([
|
||||
'dir.ngAfterViewChecked'
|
||||
]);
|
||||
}));
|
||||
|
||||
it('should be called in reverse order so the child is always notified before the parent',
|
||||
@ -984,8 +934,9 @@ export function main() {
|
||||
|
||||
ctx.detectChanges(false);
|
||||
|
||||
expect(directiveLog.filter(['ngAfterViewChecked']))
|
||||
.toEqual(['child.ngAfterViewChecked', 'parent.ngAfterViewChecked']);
|
||||
expect(directiveLog.filter(['ngAfterViewChecked'])).toEqual([
|
||||
'child.ngAfterViewChecked', 'parent.ngAfterViewChecked'
|
||||
]);
|
||||
}));
|
||||
});
|
||||
|
||||
@ -1000,18 +951,19 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should be called after processing the content and view children', fakeAsync(() => {
|
||||
var ctx = createCompFixture(
|
||||
'<div testDirective="parent"><div *ngFor="let x of [0,1]" testDirective="contentChild{{x}}"></div>' +
|
||||
'<other-cmp></other-cmp></div>',
|
||||
TestComponent,
|
||||
tcb.overrideTemplate(AnotherComponent, '<div testDirective="viewChild"></div>'));
|
||||
var ctx = createCompFixture(
|
||||
'<div testDirective="parent"><div *ngFor="let x of [0,1]" testDirective="contentChild{{x}}"></div>' +
|
||||
'<other-cmp></other-cmp></div>',
|
||||
TestComponent,
|
||||
tcb.overrideTemplate(AnotherComponent, '<div testDirective="viewChild"></div>'));
|
||||
|
||||
ctx.detectChanges(false);
|
||||
ctx.destroy();
|
||||
|
||||
expect(directiveLog.filter(['ngOnDestroy']))
|
||||
.toEqual(
|
||||
['contentChild0.ngOnDestroy', 'contentChild1.ngOnDestroy', 'viewChild.ngOnDestroy', 'parent.ngOnDestroy']);
|
||||
expect(directiveLog.filter(['ngOnDestroy'])).toEqual([
|
||||
'contentChild0.ngOnDestroy', 'contentChild1.ngOnDestroy', 'viewChild.ngOnDestroy',
|
||||
'parent.ngOnDestroy'
|
||||
]);
|
||||
}));
|
||||
|
||||
it('should be called in reverse order so the child is always notified before the parent',
|
||||
@ -1022,8 +974,9 @@ export function main() {
|
||||
ctx.detectChanges(false);
|
||||
ctx.destroy();
|
||||
|
||||
expect(directiveLog.filter(['ngOnDestroy']))
|
||||
.toEqual(['child.ngOnDestroy', 'parent.ngOnDestroy']);
|
||||
expect(directiveLog.filter(['ngOnDestroy'])).toEqual([
|
||||
'child.ngOnDestroy', 'parent.ngOnDestroy'
|
||||
]);
|
||||
}));
|
||||
|
||||
it('should call ngOnDestory on pipes', fakeAsync(() => {
|
||||
@ -1032,8 +985,9 @@ export function main() {
|
||||
ctx.detectChanges(false);
|
||||
ctx.destroy();
|
||||
|
||||
expect(directiveLog.filter(['ngOnDestroy']))
|
||||
.toEqual(['pipeWithOnDestroy.ngOnDestroy']);
|
||||
expect(directiveLog.filter(['ngOnDestroy'])).toEqual([
|
||||
'pipeWithOnDestroy.ngOnDestroy'
|
||||
]);
|
||||
}));
|
||||
});
|
||||
|
||||
@ -1095,27 +1049,17 @@ export function main() {
|
||||
}
|
||||
|
||||
const ALL_DIRECTIVES = /*@ts2dart_const*/[
|
||||
forwardRef(() => TestDirective),
|
||||
forwardRef(() => TestComponent),
|
||||
forwardRef(() => AnotherComponent),
|
||||
forwardRef(() => TestLocals),
|
||||
forwardRef(() => CompWithRef),
|
||||
forwardRef(() => EmitterDirective),
|
||||
forwardRef(() => PushComp),
|
||||
forwardRef(() => OrderCheckDirective2),
|
||||
forwardRef(() => OrderCheckDirective0),
|
||||
forwardRef(() => OrderCheckDirective1),
|
||||
NgFor
|
||||
forwardRef(() => TestDirective), forwardRef(() => TestComponent),
|
||||
forwardRef(() => AnotherComponent), forwardRef(() => TestLocals), forwardRef(() => CompWithRef),
|
||||
forwardRef(() => EmitterDirective), forwardRef(() => PushComp),
|
||||
forwardRef(() => OrderCheckDirective2), forwardRef(() => OrderCheckDirective0),
|
||||
forwardRef(() => OrderCheckDirective1), NgFor
|
||||
];
|
||||
|
||||
const ALL_PIPES = /*@ts2dart_const*/[
|
||||
forwardRef(() => CountingPipe),
|
||||
forwardRef(() => CountingImpurePipe),
|
||||
forwardRef(() => MultiArgPipe),
|
||||
forwardRef(() => PipeWithOnDestroy),
|
||||
forwardRef(() => IdentityPipe),
|
||||
forwardRef(() => WrappedPipe),
|
||||
AsyncPipe
|
||||
forwardRef(() => CountingPipe), forwardRef(() => CountingImpurePipe),
|
||||
forwardRef(() => MultiArgPipe), forwardRef(() => PipeWithOnDestroy),
|
||||
forwardRef(() => IdentityPipe), forwardRef(() => WrappedPipe), AsyncPipe
|
||||
];
|
||||
|
||||
@Injectable()
|
||||
@ -1213,7 +1157,11 @@ class WrappedPipe implements PipeTransform {
|
||||
|
||||
@Pipe({name: 'multiArgPipe'})
|
||||
class MultiArgPipe implements PipeTransform {
|
||||
transform(value: any /** TODO #9100 */, arg1: any /** TODO #9100 */, arg2: any /** TODO #9100 */, arg3 = 'default') { return `${value} ${arg1} ${arg2} ${arg3}`; }
|
||||
transform(
|
||||
value: any /** TODO #9100 */, arg1: any /** TODO #9100 */, arg2: any /** TODO #9100 */,
|
||||
arg3 = 'default') {
|
||||
return `${value} ${arg1} ${arg2} ${arg3}`;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'test-cmp', template: '', directives: ALL_DIRECTIVES, pipes: ALL_PIPES})
|
||||
@ -1292,7 +1240,9 @@ class TestDirective implements OnInit, DoCheck, OnChanges, AfterContentInit, Aft
|
||||
ngOnChanges(changes: any /** TODO #9100 */) {
|
||||
this.log.add(this.name, 'ngOnChanges');
|
||||
var r = {};
|
||||
StringMapWrapper.forEach(changes, (c: any /** TODO #9100 */, key: any /** TODO #9100 */) => (r as any /** TODO #9100 */)[key] = c.currentValue);
|
||||
StringMapWrapper.forEach(
|
||||
changes, (c: any /** TODO #9100 */, key: any /** TODO #9100 */) =>
|
||||
(r as any /** TODO #9100 */)[key] = c.currentValue);
|
||||
this.changes = r;
|
||||
if (this.throwOn == 'ngOnChanges') {
|
||||
throw new BaseException('Boom!');
|
||||
|
@ -1,15 +1,4 @@
|
||||
import {
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
xdescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
beforeEachProviders,
|
||||
it,
|
||||
xit,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
|
||||
import {Predicate} from '../../src/facade/collection';
|
||||
@ -25,39 +14,42 @@ import {el} from '@angular/platform-browser/testing';
|
||||
|
||||
export function main() {
|
||||
describe('DynamicComponentLoader', function() {
|
||||
describe("loading next to a location", () => {
|
||||
describe('loading next to a location', () => {
|
||||
it('should work',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.createAsync(MyComp3).then((tc) => {
|
||||
tc.detectChanges();
|
||||
loader.loadNextToLocation(DynamicallyLoaded,
|
||||
tc.componentInstance.viewContainerRef)
|
||||
.then(ref => {
|
||||
expect(tc.debugElement.nativeElement).toHaveText('DynamicallyLoaded;');
|
||||
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should return a disposable component ref',
|
||||
inject(
|
||||
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder,
|
||||
async: AsyncTestCompleter) => {
|
||||
tcb.createAsync(MyComp3).then((tc) => {
|
||||
tc.detectChanges();
|
||||
loader.loadNextToLocation(DynamicallyLoaded, tc.componentInstance.viewContainerRef)
|
||||
.then(ref => {
|
||||
loader.loadNextToLocation(DynamicallyLoaded2,
|
||||
tc.componentInstance.viewContainerRef)
|
||||
expect(tc.debugElement.nativeElement).toHaveText('DynamicallyLoaded;');
|
||||
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should return a disposable component ref',
|
||||
inject(
|
||||
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder,
|
||||
async: AsyncTestCompleter) => {
|
||||
tcb.createAsync(MyComp3).then((tc) => {
|
||||
tc.detectChanges();
|
||||
loader.loadNextToLocation(DynamicallyLoaded, tc.componentInstance.viewContainerRef)
|
||||
.then(ref => {
|
||||
loader
|
||||
.loadNextToLocation(
|
||||
DynamicallyLoaded2, tc.componentInstance.viewContainerRef)
|
||||
.then(ref2 => {
|
||||
expect(tc.debugElement.nativeElement)
|
||||
.toHaveText("DynamicallyLoaded;DynamicallyLoaded2;");
|
||||
.toHaveText('DynamicallyLoaded;DynamicallyLoaded2;');
|
||||
|
||||
ref2.destroy();
|
||||
|
||||
expect(tc.debugElement.nativeElement).toHaveText("DynamicallyLoaded;");
|
||||
expect(tc.debugElement.nativeElement).toHaveText('DynamicallyLoaded;');
|
||||
|
||||
async.done();
|
||||
});
|
||||
@ -66,118 +58,135 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should update host properties',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.createAsync(MyComp3).then((tc) => {
|
||||
tc.detectChanges();
|
||||
inject(
|
||||
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder,
|
||||
async: AsyncTestCompleter) => {
|
||||
tcb.createAsync(MyComp3).then((tc) => {
|
||||
tc.detectChanges();
|
||||
|
||||
loader.loadNextToLocation(DynamicallyLoadedWithHostProps,
|
||||
tc.componentInstance.viewContainerRef)
|
||||
.then(ref => {
|
||||
ref.instance.id = "new value";
|
||||
loader
|
||||
.loadNextToLocation(
|
||||
DynamicallyLoadedWithHostProps, tc.componentInstance.viewContainerRef)
|
||||
.then(ref => {
|
||||
ref.instance.id = 'new value';
|
||||
|
||||
tc.detectChanges();
|
||||
tc.detectChanges();
|
||||
|
||||
var newlyInsertedElement = tc.debugElement.childNodes[1].nativeNode;
|
||||
expect((<HTMLElement>newlyInsertedElement).id).toEqual("new value");
|
||||
var newlyInsertedElement = tc.debugElement.childNodes[1].nativeNode;
|
||||
expect((<HTMLElement>newlyInsertedElement).id).toEqual('new value');
|
||||
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
|
||||
it('should leave the view tree in a consistent state if hydration fails',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.createAsync(MyComp3).then((tc: ComponentFixture<any>) => {
|
||||
tc.detectChanges();
|
||||
PromiseWrapper.catchError(
|
||||
loader.loadNextToLocation(DynamicallyLoadedThrows,
|
||||
tc.componentInstance.viewContainerRef),
|
||||
(error) => {
|
||||
expect(error.message).toContain("ThrownInConstructor");
|
||||
expect(() => tc.detectChanges()).not.toThrow();
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}));
|
||||
inject(
|
||||
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder,
|
||||
async: AsyncTestCompleter) => {
|
||||
tcb.createAsync(MyComp3).then((tc: ComponentFixture<any>) => {
|
||||
tc.detectChanges();
|
||||
PromiseWrapper.catchError(
|
||||
loader.loadNextToLocation(
|
||||
DynamicallyLoadedThrows, tc.componentInstance.viewContainerRef),
|
||||
(error) => {
|
||||
expect(error.message).toContain('ThrownInConstructor');
|
||||
expect(() => tc.detectChanges()).not.toThrow();
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should allow to pass projectable nodes',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.createAsync(MyComp3).then((tc) => {
|
||||
tc.detectChanges();
|
||||
loader.loadNextToLocation(DynamicallyLoadedWithNgContent,
|
||||
tc.componentInstance.viewContainerRef, null,
|
||||
[[getDOM().createTextNode('hello')]])
|
||||
.then(ref => {
|
||||
tc.detectChanges();
|
||||
var newlyInsertedElement = tc.debugElement.childNodes[1].nativeNode;
|
||||
expect(newlyInsertedElement).toHaveText('dynamic(hello)');
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
inject(
|
||||
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder,
|
||||
async: AsyncTestCompleter) => {
|
||||
tcb.createAsync(MyComp3).then((tc) => {
|
||||
tc.detectChanges();
|
||||
loader
|
||||
.loadNextToLocation(
|
||||
DynamicallyLoadedWithNgContent, tc.componentInstance.viewContainerRef,
|
||||
null, [[getDOM().createTextNode('hello')]])
|
||||
.then(ref => {
|
||||
tc.detectChanges();
|
||||
var newlyInsertedElement = tc.debugElement.childNodes[1].nativeNode;
|
||||
expect(newlyInsertedElement).toHaveText('dynamic(hello)');
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not throw if not enough projectable nodes are passed in',
|
||||
inject([DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.createAsync(MyComp3).then((tc) => {
|
||||
tc.detectChanges();
|
||||
loader.loadNextToLocation(DynamicallyLoadedWithNgContent,
|
||||
tc.componentInstance.viewContainerRef, null, [])
|
||||
.then((_) => { async.done(); });
|
||||
});
|
||||
}));
|
||||
inject(
|
||||
[DynamicComponentLoader, TestComponentBuilder, AsyncTestCompleter],
|
||||
(loader: DynamicComponentLoader, tcb: TestComponentBuilder,
|
||||
async: AsyncTestCompleter) => {
|
||||
tcb.createAsync(MyComp3).then((tc) => {
|
||||
tc.detectChanges();
|
||||
loader
|
||||
.loadNextToLocation(
|
||||
DynamicallyLoadedWithNgContent, tc.componentInstance.viewContainerRef,
|
||||
null, [])
|
||||
.then((_) => { async.done(); });
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
describe('loadAsRoot', () => {
|
||||
it('should allow to create, update and destroy components',
|
||||
inject([AsyncTestCompleter, DynamicComponentLoader, DOCUMENT, Injector],
|
||||
(async: AsyncTestCompleter, loader: DynamicComponentLoader, doc: any /** TODO #9100 */, injector: Injector) => {
|
||||
var rootEl = createRootElement(doc, 'child-cmp');
|
||||
getDOM().appendChild(doc.body, rootEl);
|
||||
loader.loadAsRoot(ChildComp, null, injector)
|
||||
.then((componentRef) => {
|
||||
var el = new ComponentFixture<any>(componentRef, null, false);
|
||||
inject(
|
||||
[AsyncTestCompleter, DynamicComponentLoader, DOCUMENT, Injector],
|
||||
(async: AsyncTestCompleter, loader: DynamicComponentLoader, doc: any /** TODO #9100 */,
|
||||
injector: Injector) => {
|
||||
var rootEl = createRootElement(doc, 'child-cmp');
|
||||
getDOM().appendChild(doc.body, rootEl);
|
||||
loader.loadAsRoot(ChildComp, null, injector).then((componentRef) => {
|
||||
var el = new ComponentFixture<any>(componentRef, null, false);
|
||||
|
||||
expect(rootEl.parentNode).toBe(doc.body);
|
||||
expect(rootEl.parentNode).toBe(doc.body);
|
||||
|
||||
el.detectChanges();
|
||||
el.detectChanges();
|
||||
|
||||
expect(rootEl).toHaveText('hello');
|
||||
expect(rootEl).toHaveText('hello');
|
||||
|
||||
componentRef.instance.ctxProp = 'new';
|
||||
componentRef.instance.ctxProp = 'new';
|
||||
|
||||
el.detectChanges();
|
||||
el.detectChanges();
|
||||
|
||||
expect(rootEl).toHaveText('new');
|
||||
expect(rootEl).toHaveText('new');
|
||||
|
||||
componentRef.destroy();
|
||||
componentRef.destroy();
|
||||
|
||||
expect(rootEl.parentNode).toBeFalsy();
|
||||
expect(rootEl.parentNode).toBeFalsy();
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should allow to pass projectable nodes',
|
||||
inject([AsyncTestCompleter, DynamicComponentLoader, DOCUMENT, Injector],
|
||||
(async: AsyncTestCompleter, loader: DynamicComponentLoader, doc: any /** TODO #9100 */, injector: Injector) => {
|
||||
var rootEl = createRootElement(doc, 'dummy');
|
||||
getDOM().appendChild(doc.body, rootEl);
|
||||
loader.loadAsRoot(DynamicallyLoadedWithNgContent, null, injector, null,
|
||||
[[getDOM().createTextNode('hello')]])
|
||||
.then((_) => {
|
||||
expect(rootEl).toHaveText('dynamic(hello)');
|
||||
inject(
|
||||
[AsyncTestCompleter, DynamicComponentLoader, DOCUMENT, Injector],
|
||||
(async: AsyncTestCompleter, loader: DynamicComponentLoader, doc: any /** TODO #9100 */,
|
||||
injector: Injector) => {
|
||||
var rootEl = createRootElement(doc, 'dummy');
|
||||
getDOM().appendChild(doc.body, rootEl);
|
||||
loader
|
||||
.loadAsRoot(
|
||||
DynamicallyLoadedWithNgContent, null, injector, null,
|
||||
[[getDOM().createTextNode('hello')]])
|
||||
.then((_) => {
|
||||
expect(rootEl).toHaveText('dynamic(hello)');
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
@ -204,31 +213,31 @@ class ChildComp {
|
||||
constructor(public elementRef: ElementRef) { this.ctxProp = 'hello'; }
|
||||
}
|
||||
|
||||
@Component({selector: 'dummy', template: "DynamicallyLoaded;"})
|
||||
@Component({selector: 'dummy', template: 'DynamicallyLoaded;'})
|
||||
class DynamicallyLoaded {
|
||||
}
|
||||
|
||||
@Component({selector: 'dummy', template: "DynamicallyLoaded;"})
|
||||
@Component({selector: 'dummy', template: 'DynamicallyLoaded;'})
|
||||
class DynamicallyLoadedThrows {
|
||||
constructor() { throw new BaseException("ThrownInConstructor"); }
|
||||
constructor() { throw new BaseException('ThrownInConstructor'); }
|
||||
}
|
||||
|
||||
@Component({selector: 'dummy', template: "DynamicallyLoaded2;"})
|
||||
@Component({selector: 'dummy', template: 'DynamicallyLoaded2;'})
|
||||
class DynamicallyLoaded2 {
|
||||
}
|
||||
|
||||
@Component({selector: 'dummy', host: {'[id]': 'id'}, template: "DynamicallyLoadedWithHostProps;"})
|
||||
@Component({selector: 'dummy', host: {'[id]': 'id'}, template: 'DynamicallyLoadedWithHostProps;'})
|
||||
class DynamicallyLoadedWithHostProps {
|
||||
id: string;
|
||||
|
||||
constructor() { this.id = "default"; }
|
||||
constructor() { this.id = 'default'; }
|
||||
}
|
||||
|
||||
@Component({selector: 'dummy', template: "dynamic(<ng-content></ng-content>)"})
|
||||
@Component({selector: 'dummy', template: 'dynamic(<ng-content></ng-content>)'})
|
||||
class DynamicallyLoadedWithNgContent {
|
||||
id: string;
|
||||
|
||||
constructor() { this.id = "default"; }
|
||||
constructor() { this.id = 'default'; }
|
||||
}
|
||||
|
||||
@Component({selector: 'my-comp', directives: [], template: '<div #loc></div>'})
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,16 +1,5 @@
|
||||
import {
|
||||
describe,
|
||||
it,
|
||||
expect,
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
iit,
|
||||
xit,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {
|
||||
fakeAsync,
|
||||
tick,
|
||||
} from '@angular/core/testing';
|
||||
import {describe, it, expect, beforeEach, ddescribe, iit, xit,} from '@angular/core/testing/testing_internal';
|
||||
import {fakeAsync, tick,} from '@angular/core/testing';
|
||||
import {MapWrapper, ListWrapper, iterateListLike} from '../../src/facade/collection';
|
||||
import {IS_DART, StringWrapper} from '../../src/facade/lang';
|
||||
import {ObservableWrapper} from '../../src/facade/async';
|
||||
@ -61,22 +50,28 @@ export function main() {
|
||||
if (!IS_DART) {
|
||||
it('should support filter', () => {
|
||||
queryList.reset(['one', 'two']);
|
||||
expect((<_JsQueryList>queryList).filter((x: any /** TODO #9100 */) => x == "one")).toEqual(['one']);
|
||||
expect((<_JsQueryList>queryList).filter((x: any /** TODO #9100 */) => x == 'one')).toEqual([
|
||||
'one'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should support reduce', () => {
|
||||
queryList.reset(["one", "two"]);
|
||||
expect((<_JsQueryList>queryList).reduce((a: any /** TODO #9100 */, x: any /** TODO #9100 */) => a + x, "start:")).toEqual("start:onetwo");
|
||||
queryList.reset(['one', 'two']);
|
||||
expect((<_JsQueryList>queryList)
|
||||
.reduce((a: any /** TODO #9100 */, x: any /** TODO #9100 */) => a + x, 'start:'))
|
||||
.toEqual('start:onetwo');
|
||||
});
|
||||
|
||||
it('should support toArray', () => {
|
||||
queryList.reset(["one", "two"]);
|
||||
expect((<_JsQueryList>queryList).reduce((a: any /** TODO #9100 */, x: any /** TODO #9100 */) => a + x, "start:")).toEqual("start:onetwo");
|
||||
queryList.reset(['one', 'two']);
|
||||
expect((<_JsQueryList>queryList)
|
||||
.reduce((a: any /** TODO #9100 */, x: any /** TODO #9100 */) => a + x, 'start:'))
|
||||
.toEqual('start:onetwo');
|
||||
});
|
||||
|
||||
it('should support toArray', () => {
|
||||
queryList.reset(["one", "two"]);
|
||||
expect((<_JsQueryList>queryList).toArray()).toEqual(["one", "two"]);
|
||||
queryList.reset(['one', 'two']);
|
||||
expect((<_JsQueryList>queryList).toArray()).toEqual(['one', 'two']);
|
||||
});
|
||||
}
|
||||
|
||||
@ -114,7 +109,7 @@ export function main() {
|
||||
var recorded: any /** TODO #9100 */;
|
||||
ObservableWrapper.subscribe(queryList.changes, (v: any) => { recorded = v; });
|
||||
|
||||
queryList.reset(["one"]);
|
||||
queryList.reset(['one']);
|
||||
queryList.notifyOnChanges();
|
||||
tick();
|
||||
|
||||
|
@ -1,25 +1,9 @@
|
||||
import {
|
||||
ddescribe,
|
||||
describe,
|
||||
xdescribe,
|
||||
it,
|
||||
iit,
|
||||
xit,
|
||||
expect,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
inject,
|
||||
beforeEachProviders
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {provide} from '@angular/core';
|
||||
import {
|
||||
ComponentResolver,
|
||||
ReflectorComponentResolver
|
||||
} from '@angular/core/src/linker/component_resolver';
|
||||
import {reflector, ReflectionInfo} from '@angular/core/src/reflection/reflection';
|
||||
import {ComponentFactory} from '@angular/core/src/linker/component_factory';
|
||||
import {ComponentResolver, ReflectorComponentResolver} from '@angular/core/src/linker/component_resolver';
|
||||
import {ReflectionInfo, reflector} from '@angular/core/src/reflection/reflection';
|
||||
import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
|
||||
export function main() {
|
||||
describe('Compiler', () => {
|
||||
@ -33,23 +17,25 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should read the template from an annotation',
|
||||
inject([AsyncTestCompleter, ComponentResolver], (async: AsyncTestCompleter, compiler: ComponentResolver) => {
|
||||
compiler.resolveComponent(SomeComponent)
|
||||
.then((compFactory: ComponentFactory<any>) => {
|
||||
inject(
|
||||
[AsyncTestCompleter, ComponentResolver],
|
||||
(async: AsyncTestCompleter, compiler: ComponentResolver) => {
|
||||
compiler.resolveComponent(SomeComponent).then((compFactory: ComponentFactory<any>) => {
|
||||
expect(compFactory).toBe(someCompFactory);
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
it('should throw when given a string',
|
||||
inject([AsyncTestCompleter, ComponentResolver], (async: AsyncTestCompleter, compiler: ComponentResolver) => {
|
||||
compiler.resolveComponent("someString")
|
||||
.catch((e) => {
|
||||
expect(e.message).toContain("Cannot resolve component using 'someString'.")
|
||||
async.done();
|
||||
inject(
|
||||
[AsyncTestCompleter, ComponentResolver],
|
||||
(async: AsyncTestCompleter, compiler: ComponentResolver) => {
|
||||
compiler.resolveComponent('someString').catch((e) => {
|
||||
expect(e.message).toContain('Cannot resolve component using \'someString\'.')
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,30 +1,10 @@
|
||||
import {
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
xdescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
beforeEachProviders,
|
||||
it,
|
||||
xit,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
|
||||
import {TestComponentBuilder} from '@angular/compiler/testing';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {IS_DART} from '../../src/facade/lang';
|
||||
|
||||
import {
|
||||
Component,
|
||||
Pipe,
|
||||
PipeTransform,
|
||||
provide,
|
||||
ViewMetadata,
|
||||
PLATFORM_PIPES,
|
||||
OpaqueToken,
|
||||
Injector
|
||||
} from '@angular/core';
|
||||
import {Component, Pipe, PipeTransform, provide, ViewMetadata, PLATFORM_PIPES, OpaqueToken, Injector} from '@angular/core';
|
||||
import {NgIf, NgClass} from '@angular/common';
|
||||
import {CompilerConfig} from '@angular/compiler';
|
||||
|
||||
@ -54,44 +34,50 @@ function declareTests(isJit: boolean) {
|
||||
beforeEachProviders(() => [{provide: PLATFORM_PIPES, useValue: [PlatformPipe], multi: true}]);
|
||||
|
||||
it('should overwrite them by custom pipes',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.overrideView(
|
||||
MyComp1, new ViewMetadata({template: '{{true | somePipe}}', pipes: [CustomPipe]}))
|
||||
.createAsync(MyComp1)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('someCustomPipe');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
inject(
|
||||
[TestComponentBuilder, AsyncTestCompleter],
|
||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.overrideView(
|
||||
MyComp1,
|
||||
new ViewMetadata({template: '{{true | somePipe}}', pipes: [CustomPipe]}))
|
||||
.createAsync(MyComp1)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('someCustomPipe');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('expressions', () => {
|
||||
|
||||
it('should evaluate conditional and boolean operators with right precedence - #8244',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.overrideView(MyComp1,
|
||||
new ViewMetadata({template: `{{'red' + (true ? ' border' : '')}}`}))
|
||||
.createAsync(MyComp1)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('red border');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
inject(
|
||||
[TestComponentBuilder, AsyncTestCompleter],
|
||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.overrideView(
|
||||
MyComp1, new ViewMetadata({template: `{{'red' + (true ? ' border' : '')}}`}))
|
||||
.createAsync(MyComp1)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('red border');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
if (!IS_DART) {
|
||||
it('should evaluate conditional and unary operators with right precedence - #8235',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter],
|
||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.overrideView(MyComp1, new ViewMetadata({template: `{{!null?.length}}`}))
|
||||
.createAsync(MyComp1)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('true');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
inject(
|
||||
[TestComponentBuilder, AsyncTestCompleter],
|
||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.overrideView(MyComp1, new ViewMetadata({template: `{{!null?.length}}`}))
|
||||
.createAsync(MyComp1)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('true');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
@ -103,80 +89,96 @@ function declareTests(isJit: boolean) {
|
||||
}
|
||||
|
||||
it('should support providers with an OpaqueToken that contains a `.` in the name',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
var token = new OpaqueToken('a.b');
|
||||
var tokenValue = 1;
|
||||
createInjector(tcb, [{provide: token, useValue: tokenValue}])
|
||||
.then((injector: Injector) => {
|
||||
inject(
|
||||
[TestComponentBuilder, AsyncTestCompleter],
|
||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
var token = new OpaqueToken('a.b');
|
||||
var tokenValue = 1;
|
||||
createInjector(tcb, [
|
||||
{provide: token, useValue: tokenValue}
|
||||
]).then((injector: Injector) => {
|
||||
expect(injector.get(token)).toEqual(tokenValue);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
it('should support providers with string token with a `.` in it',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
var token = 'a.b';
|
||||
var tokenValue = 1;
|
||||
createInjector(tcb, [{provide: token, useValue: tokenValue}])
|
||||
.then((injector: Injector) => {
|
||||
inject(
|
||||
[TestComponentBuilder, AsyncTestCompleter],
|
||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
var token = 'a.b';
|
||||
var tokenValue = 1;
|
||||
createInjector(tcb, [
|
||||
{provide: token, useValue: tokenValue}
|
||||
]).then((injector: Injector) => {
|
||||
expect(injector.get(token)).toEqual(tokenValue);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
it('should support providers with an anonymous function',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
var token = () => true;
|
||||
var tokenValue = 1;
|
||||
createInjector(tcb, [{provide: token, useValue: tokenValue}])
|
||||
.then((injector: Injector) => {
|
||||
inject(
|
||||
[TestComponentBuilder, AsyncTestCompleter],
|
||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
var token = () => true;
|
||||
var tokenValue = 1;
|
||||
createInjector(tcb, [
|
||||
{provide: token, useValue: tokenValue}
|
||||
]).then((injector: Injector) => {
|
||||
expect(injector.get(token)).toEqual(tokenValue);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
it('should support providers with an OpaqueToken that has a StringMap as value',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
var token1 = new OpaqueToken('someToken');
|
||||
var token2 = new OpaqueToken('someToken');
|
||||
var tokenValue1 = {'a': 1};
|
||||
var tokenValue2 = {'a': 1};
|
||||
createInjector(
|
||||
tcb,
|
||||
[{provide: token1, useValue: tokenValue1}, {provide: token2, useValue: tokenValue2}])
|
||||
.then((injector: Injector) => {
|
||||
inject(
|
||||
[TestComponentBuilder, AsyncTestCompleter],
|
||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
var token1 = new OpaqueToken('someToken');
|
||||
var token2 = new OpaqueToken('someToken');
|
||||
var tokenValue1 = {'a': 1};
|
||||
var tokenValue2 = {'a': 1};
|
||||
createInjector(tcb, [
|
||||
{provide: token1, useValue: tokenValue1},
|
||||
{provide: token2, useValue: tokenValue2}
|
||||
]).then((injector: Injector) => {
|
||||
expect(injector.get(token1)).toEqual(tokenValue1);
|
||||
expect(injector.get(token2)).toEqual(tokenValue2);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
}));
|
||||
});
|
||||
|
||||
it('should allow logging a previous elements class binding via interpolation',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.overrideTemplate(MyComp1, `<div [class.a]="true" #el>Class: {{el.className}}</div>`)
|
||||
.createAsync(MyComp1)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('Class: a');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
inject(
|
||||
[TestComponentBuilder, AsyncTestCompleter],
|
||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.overrideTemplate(
|
||||
MyComp1, `<div [class.a]="true" #el>Class: {{el.className}}</div>`)
|
||||
.createAsync(MyComp1)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('Class: a');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should support ngClass before a component and content projection inside of an ngIf',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.overrideView(
|
||||
MyComp1, new ViewMetadata({
|
||||
template: `A<cmp-content *ngIf="true" [ngClass]="'red'">B</cmp-content>C`,
|
||||
directives: [NgClass, NgIf, CmpWithNgContent]
|
||||
}))
|
||||
.createAsync(MyComp1)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('ABC');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
inject(
|
||||
[TestComponentBuilder, AsyncTestCompleter],
|
||||
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||
tcb.overrideView(
|
||||
MyComp1, new ViewMetadata({
|
||||
template: `A<cmp-content *ngIf="true" [ngClass]="'red'">B</cmp-content>C`,
|
||||
directives: [NgClass, NgIf, CmpWithNgContent]
|
||||
}))
|
||||
.createAsync(MyComp1)
|
||||
.then((fixture) => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('ABC');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
});
|
||||
|
@ -1,13 +1,4 @@
|
||||
import {
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
inject,
|
||||
beforeEachProviders,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
it,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {ddescribe, describe, expect, inject, beforeEachProviders, beforeEach, afterEach, it,} from '@angular/core/testing/testing_internal';
|
||||
import {TestComponentBuilder} from '@angular/compiler/testing';
|
||||
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
@ -48,10 +39,11 @@ class SecuredComponent {
|
||||
}
|
||||
|
||||
function itAsync(msg: string, injections: Function[], f: Function): any; /** TODO #???? */
|
||||
function itAsync(msg: string, f: (tcb: TestComponentBuilder, atc: AsyncTestCompleter) => void): any; /** TODO #???? */
|
||||
function itAsync(msg: string,
|
||||
f: Function[] | ((tcb: TestComponentBuilder, atc: AsyncTestCompleter) => void),
|
||||
fn?: Function): any /** TODO #???? */ {
|
||||
function itAsync(msg: string, f: (tcb: TestComponentBuilder, atc: AsyncTestCompleter) => void):
|
||||
any; /** TODO #???? */
|
||||
function itAsync(
|
||||
msg: string, f: Function[] | ((tcb: TestComponentBuilder, atc: AsyncTestCompleter) => void),
|
||||
fn?: Function): any /** TODO #???? */ {
|
||||
if (f instanceof Function) {
|
||||
it(msg, inject([TestComponentBuilder, AsyncTestCompleter], <Function>f));
|
||||
} else {
|
||||
@ -73,129 +65,140 @@ function declareTests(isJit: boolean) {
|
||||
afterEach(() => { getDOM().log = originalLog; });
|
||||
|
||||
|
||||
itAsync('should disallow binding on*', (tcb: TestComponentBuilder, async: any /** TODO #???? */) => {
|
||||
let tpl = `<div [attr.onclick]="ctxProp"></div>`;
|
||||
tcb = tcb.overrideView(SecuredComponent, new ViewMetadata({template: tpl}));
|
||||
PromiseWrapper.catchError(tcb.createAsync(SecuredComponent), (e) => {
|
||||
expect(e.message).toContain(`Template parse errors:\n` +
|
||||
`Binding to event attribute 'onclick' is disallowed ` +
|
||||
`for security reasons, please use (click)=... `);
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
});
|
||||
itAsync(
|
||||
'should disallow binding on*',
|
||||
(tcb: TestComponentBuilder, async: any /** TODO #???? */) => {
|
||||
let tpl = `<div [attr.onclick]="ctxProp"></div>`;
|
||||
tcb = tcb.overrideView(SecuredComponent, new ViewMetadata({template: tpl}));
|
||||
PromiseWrapper.catchError(tcb.createAsync(SecuredComponent), (e) => {
|
||||
expect(e.message).toContain(
|
||||
`Template parse errors:\n` +
|
||||
`Binding to event attribute 'onclick' is disallowed ` +
|
||||
`for security reasons, please use (click)=... `);
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
describe('safe HTML values', function() {
|
||||
itAsync('should not escape values marked as trusted',
|
||||
[TestComponentBuilder, AsyncTestCompleter, DomSanitizationService],
|
||||
(tcb: TestComponentBuilder, async: any /** TODO #???? */, sanitizer: DomSanitizationService) => {
|
||||
let tpl = `<a [href]="ctxProp">Link Title</a>`;
|
||||
tcb.overrideView(SecuredComponent,
|
||||
new ViewMetadata({template: tpl, directives: []}))
|
||||
.createAsync(SecuredComponent)
|
||||
.then((fixture) => {
|
||||
let e = fixture.debugElement.children[0].nativeElement;
|
||||
let ci = fixture.debugElement.componentInstance;
|
||||
let trusted = sanitizer.bypassSecurityTrustUrl('javascript:alert(1)');
|
||||
ci.ctxProp = trusted;
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getProperty(e, 'href')).toEqual('javascript:alert(1)');
|
||||
itAsync(
|
||||
'should not escape values marked as trusted',
|
||||
[TestComponentBuilder, AsyncTestCompleter, DomSanitizationService],
|
||||
(tcb: TestComponentBuilder, async: any /** TODO #???? */,
|
||||
sanitizer: DomSanitizationService) => {
|
||||
let tpl = `<a [href]="ctxProp">Link Title</a>`;
|
||||
tcb.overrideView(SecuredComponent, new ViewMetadata({template: tpl, directives: []}))
|
||||
.createAsync(SecuredComponent)
|
||||
.then((fixture) => {
|
||||
let e = fixture.debugElement.children[0].nativeElement;
|
||||
let ci = fixture.debugElement.componentInstance;
|
||||
let trusted = sanitizer.bypassSecurityTrustUrl('javascript:alert(1)');
|
||||
ci.ctxProp = trusted;
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getProperty(e, 'href')).toEqual('javascript:alert(1)');
|
||||
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
|
||||
itAsync('should error when using the wrong trusted value',
|
||||
[TestComponentBuilder, AsyncTestCompleter, DomSanitizationService],
|
||||
(tcb: TestComponentBuilder, async: any /** TODO #???? */, sanitizer: DomSanitizationService) => {
|
||||
let tpl = `<a [href]="ctxProp">Link Title</a>`;
|
||||
tcb.overrideView(SecuredComponent,
|
||||
new ViewMetadata({template: tpl, directives: []}))
|
||||
.createAsync(SecuredComponent)
|
||||
.then((fixture) => {
|
||||
let trusted = sanitizer.bypassSecurityTrustScript('javascript:alert(1)');
|
||||
let ci = fixture.debugElement.componentInstance;
|
||||
ci.ctxProp = trusted;
|
||||
expect(() => fixture.detectChanges())
|
||||
.toThrowErrorWith('Required a safe URL, got a Script');
|
||||
itAsync(
|
||||
'should error when using the wrong trusted value',
|
||||
[TestComponentBuilder, AsyncTestCompleter, DomSanitizationService],
|
||||
(tcb: TestComponentBuilder, async: any /** TODO #???? */,
|
||||
sanitizer: DomSanitizationService) => {
|
||||
let tpl = `<a [href]="ctxProp">Link Title</a>`;
|
||||
tcb.overrideView(SecuredComponent, new ViewMetadata({template: tpl, directives: []}))
|
||||
.createAsync(SecuredComponent)
|
||||
.then((fixture) => {
|
||||
let trusted = sanitizer.bypassSecurityTrustScript('javascript:alert(1)');
|
||||
let ci = fixture.debugElement.componentInstance;
|
||||
ci.ctxProp = trusted;
|
||||
expect(() => fixture.detectChanges())
|
||||
.toThrowErrorWith('Required a safe URL, got a Script');
|
||||
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('sanitizing', () => {
|
||||
itAsync('should escape unsafe attributes', (tcb: TestComponentBuilder, async: any /** TODO #???? */) => {
|
||||
let tpl = `<a [href]="ctxProp">Link Title</a>`;
|
||||
tcb.overrideView(SecuredComponent, new ViewMetadata({template: tpl, directives: []}))
|
||||
.createAsync(SecuredComponent)
|
||||
.then((fixture) => {
|
||||
let e = fixture.debugElement.children[0].nativeElement;
|
||||
let ci = fixture.debugElement.componentInstance;
|
||||
ci.ctxProp = 'hello';
|
||||
fixture.detectChanges();
|
||||
// In the browser, reading href returns an absolute URL. On the server side,
|
||||
// it just echoes back the property.
|
||||
expect(getDOM().getProperty(e, 'href')).toMatch(/.*\/?hello$/);
|
||||
itAsync(
|
||||
'should escape unsafe attributes',
|
||||
(tcb: TestComponentBuilder, async: any /** TODO #???? */) => {
|
||||
let tpl = `<a [href]="ctxProp">Link Title</a>`;
|
||||
tcb.overrideView(SecuredComponent, new ViewMetadata({template: tpl, directives: []}))
|
||||
.createAsync(SecuredComponent)
|
||||
.then((fixture) => {
|
||||
let e = fixture.debugElement.children[0].nativeElement;
|
||||
let ci = fixture.debugElement.componentInstance;
|
||||
ci.ctxProp = 'hello';
|
||||
fixture.detectChanges();
|
||||
// In the browser, reading href returns an absolute URL. On the server side,
|
||||
// it just echoes back the property.
|
||||
expect(getDOM().getProperty(e, 'href')).toMatch(/.*\/?hello$/);
|
||||
|
||||
ci.ctxProp = 'javascript:alert(1)';
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getProperty(e, 'href')).toEqual('unsafe:javascript:alert(1)');
|
||||
ci.ctxProp = 'javascript:alert(1)';
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getProperty(e, 'href')).toEqual('unsafe:javascript:alert(1)');
|
||||
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
|
||||
itAsync('should escape unsafe style values', (tcb: TestComponentBuilder, async: any /** TODO #???? */) => {
|
||||
let tpl = `<div [style.background]="ctxProp">Text</div>`;
|
||||
tcb.overrideView(SecuredComponent, new ViewMetadata({template: tpl, directives: []}))
|
||||
.createAsync(SecuredComponent)
|
||||
.then((fixture) => {
|
||||
let e = fixture.debugElement.children[0].nativeElement;
|
||||
let ci = fixture.debugElement.componentInstance;
|
||||
// Make sure binding harmless values works.
|
||||
ci.ctxProp = 'red';
|
||||
fixture.detectChanges();
|
||||
// In some browsers, this will contain the full background specification, not just
|
||||
// the color.
|
||||
expect(getDOM().getStyle(e, 'background')).toMatch(/red.*/);
|
||||
itAsync(
|
||||
'should escape unsafe style values',
|
||||
(tcb: TestComponentBuilder, async: any /** TODO #???? */) => {
|
||||
let tpl = `<div [style.background]="ctxProp">Text</div>`;
|
||||
tcb.overrideView(SecuredComponent, new ViewMetadata({template: tpl, directives: []}))
|
||||
.createAsync(SecuredComponent)
|
||||
.then((fixture) => {
|
||||
let e = fixture.debugElement.children[0].nativeElement;
|
||||
let ci = fixture.debugElement.componentInstance;
|
||||
// Make sure binding harmless values works.
|
||||
ci.ctxProp = 'red';
|
||||
fixture.detectChanges();
|
||||
// In some browsers, this will contain the full background specification, not just
|
||||
// the color.
|
||||
expect(getDOM().getStyle(e, 'background')).toMatch(/red.*/);
|
||||
|
||||
ci.ctxProp = 'url(javascript:evil())';
|
||||
fixture.detectChanges();
|
||||
// Updated value gets rejected, no value change.
|
||||
expect(getDOM().getStyle(e, 'background')).not.toContain('javascript');
|
||||
ci.ctxProp = 'url(javascript:evil())';
|
||||
fixture.detectChanges();
|
||||
// Updated value gets rejected, no value change.
|
||||
expect(getDOM().getStyle(e, 'background')).not.toContain('javascript');
|
||||
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
|
||||
itAsync('should escape unsafe HTML values', (tcb: TestComponentBuilder, async: any /** TODO #???? */) => {
|
||||
let tpl = `<div [innerHTML]="ctxProp">Text</div>`;
|
||||
tcb.overrideView(SecuredComponent, new ViewMetadata({template: tpl, directives: []}))
|
||||
.createAsync(SecuredComponent)
|
||||
.then((fixture) => {
|
||||
let e = fixture.debugElement.children[0].nativeElement;
|
||||
let ci = fixture.debugElement.componentInstance;
|
||||
// Make sure binding harmless values works.
|
||||
ci.ctxProp = 'some <p>text</p>';
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getInnerHTML(e)).toEqual('some <p>text</p>');
|
||||
itAsync(
|
||||
'should escape unsafe HTML values',
|
||||
(tcb: TestComponentBuilder, async: any /** TODO #???? */) => {
|
||||
let tpl = `<div [innerHTML]="ctxProp">Text</div>`;
|
||||
tcb.overrideView(SecuredComponent, new ViewMetadata({template: tpl, directives: []}))
|
||||
.createAsync(SecuredComponent)
|
||||
.then((fixture) => {
|
||||
let e = fixture.debugElement.children[0].nativeElement;
|
||||
let ci = fixture.debugElement.componentInstance;
|
||||
// Make sure binding harmless values works.
|
||||
ci.ctxProp = 'some <p>text</p>';
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getInnerHTML(e)).toEqual('some <p>text</p>');
|
||||
|
||||
ci.ctxProp = 'ha <script>evil()</script>';
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getInnerHTML(e)).toEqual('ha evil()');
|
||||
ci.ctxProp = 'ha <script>evil()</script>';
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getInnerHTML(e)).toEqual('ha evil()');
|
||||
|
||||
ci.ctxProp = 'also <img src="x" onerror="evil()"> evil';
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getInnerHTML(e)).toEqual('also <img src="x"> evil');
|
||||
ci.ctxProp = 'also <img src="x" onerror="evil()"> evil';
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getInnerHTML(e)).toEqual('also <img src="x"> evil');
|
||||
|
||||
ci.ctxProp = 'also <iframe srcdoc="evil"> evil';
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getInnerHTML(e)).toEqual('also evil');
|
||||
ci.ctxProp = 'also <iframe srcdoc="evil"> evil';
|
||||
fixture.detectChanges();
|
||||
expect(getDOM().getInnerHTML(e)).toEqual('also evil');
|
||||
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,42 +1,8 @@
|
||||
import {
|
||||
describe,
|
||||
ddescribe,
|
||||
it,
|
||||
iit,
|
||||
xit,
|
||||
xdescribe,
|
||||
expect,
|
||||
beforeEach,
|
||||
beforeEachProviders,
|
||||
inject,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {describe, ddescribe, it, iit, xit, xdescribe, expect, beforeEach, beforeEachProviders, inject,} from '@angular/core/testing/testing_internal';
|
||||
import {fakeAsync, flushMicrotasks, Log, tick, containsRegexp} from '@angular/core/testing';
|
||||
import {TestComponentBuilder, ComponentFixture} from '@angular/compiler/testing';
|
||||
import {isBlank} from '../../src/facade/lang';
|
||||
import {
|
||||
Type,
|
||||
ViewContainerRef,
|
||||
TemplateRef,
|
||||
ElementRef,
|
||||
ChangeDetectorRef,
|
||||
ChangeDetectionStrategy,
|
||||
Directive,
|
||||
Component,
|
||||
DebugElement,
|
||||
forwardRef,
|
||||
Input,
|
||||
PipeTransform,
|
||||
Attribute,
|
||||
ViewMetadata,
|
||||
provide,
|
||||
Optional,
|
||||
Inject,
|
||||
Self,
|
||||
InjectMetadata,
|
||||
Pipe,
|
||||
Host,
|
||||
SkipSelfMetadata
|
||||
} from '@angular/core';
|
||||
import {Type, ViewContainerRef, TemplateRef, ElementRef, ChangeDetectorRef, ChangeDetectionStrategy, Directive, Component, DebugElement, forwardRef, Input, PipeTransform, Attribute, ViewMetadata, provide, Optional, Inject, Self, InjectMetadata, Pipe, Host, SkipSelfMetadata} from '@angular/core';
|
||||
import {NgIf, NgFor} from '@angular/common';
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
|
||||
@ -137,31 +103,33 @@ class NeedsDirective {
|
||||
@Directive({selector: '[needsService]'})
|
||||
class NeedsService {
|
||||
service: any;
|
||||
constructor(@Inject("service") service: any /** TODO #9100 */) { this.service = service; }
|
||||
constructor(@Inject('service') service: any /** TODO #9100 */) { this.service = service; }
|
||||
}
|
||||
|
||||
@Directive({selector: '[needsAppService]'})
|
||||
class NeedsAppService {
|
||||
service: any;
|
||||
constructor(@Inject("appService") service: any /** TODO #9100 */) { this.service = service; }
|
||||
constructor(@Inject('appService') service: any /** TODO #9100 */) { this.service = service; }
|
||||
}
|
||||
|
||||
@Component({selector: '[needsHostAppService]', template: '', directives: ALL_DIRECTIVES})
|
||||
class NeedsHostAppService {
|
||||
service: any;
|
||||
constructor(@Host() @Inject("appService") service: any /** TODO #9100 */) { this.service = service; }
|
||||
constructor(@Host() @Inject('appService') service: any /** TODO #9100 */) {
|
||||
this.service = service;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: '[needsServiceComponent]', template: ''})
|
||||
class NeedsServiceComponent {
|
||||
service: any;
|
||||
constructor(@Inject("service") service: any /** TODO #9100 */) { this.service = service; }
|
||||
constructor(@Inject('service') service: any /** TODO #9100 */) { this.service = service; }
|
||||
}
|
||||
|
||||
@Directive({selector: '[needsServiceFromHost]'})
|
||||
class NeedsServiceFromHost {
|
||||
service: any;
|
||||
constructor(@Host() @Inject("service") service: any /** TODO #9100 */) { this.service = service; }
|
||||
constructor(@Host() @Inject('service') service: any /** TODO #9100 */) { this.service = service; }
|
||||
}
|
||||
|
||||
@Directive({selector: '[needsAttribute]'})
|
||||
@ -169,8 +137,9 @@ class NeedsAttribute {
|
||||
typeAttribute: any /** TODO #9100 */;
|
||||
titleAttribute: any /** TODO #9100 */;
|
||||
fooAttribute: any /** TODO #9100 */;
|
||||
constructor(@Attribute('type') typeAttribute: String, @Attribute('title') titleAttribute: String,
|
||||
@Attribute('foo') fooAttribute: String) {
|
||||
constructor(
|
||||
@Attribute('type') typeAttribute: String, @Attribute('title') titleAttribute: String,
|
||||
@Attribute('foo') fooAttribute: String) {
|
||||
this.typeAttribute = typeAttribute;
|
||||
this.titleAttribute = titleAttribute;
|
||||
this.fooAttribute = fooAttribute;
|
||||
@ -180,7 +149,9 @@ class NeedsAttribute {
|
||||
@Directive({selector: '[needsAttributeNoType]'})
|
||||
class NeedsAttributeNoType {
|
||||
fooAttribute: any /** TODO #9100 */;
|
||||
constructor(@Attribute('foo') fooAttribute: any /** TODO #9100 */) { this.fooAttribute = fooAttribute; }
|
||||
constructor(@Attribute('foo') fooAttribute: any /** TODO #9100 */) {
|
||||
this.fooAttribute = fooAttribute;
|
||||
}
|
||||
}
|
||||
|
||||
@Directive({selector: '[needsElementRef]'})
|
||||
@ -244,7 +215,7 @@ class PipeNeedsChangeDetectorRef {
|
||||
@Pipe({name: 'pipeNeedsService'})
|
||||
export class PipeNeedsService implements PipeTransform {
|
||||
service: any;
|
||||
constructor(@Inject("service") service: any /** TODO #9100 */) { this.service = service; }
|
||||
constructor(@Inject('service') service: any /** TODO #9100 */) { this.service = service; }
|
||||
transform(value: any): any { return this; }
|
||||
}
|
||||
|
||||
@ -265,39 +236,40 @@ class TestComp {
|
||||
export function main() {
|
||||
var tcb: TestComponentBuilder;
|
||||
|
||||
function createCompFixture(template: string, tcb: TestComponentBuilder,
|
||||
comp: Type = null): ComponentFixture<any> {
|
||||
function createCompFixture(
|
||||
template: string, tcb: TestComponentBuilder, comp: Type = null): ComponentFixture<any> {
|
||||
if (isBlank(comp)) {
|
||||
comp = TestComp;
|
||||
}
|
||||
return tcb.overrideView(comp,
|
||||
new ViewMetadata(
|
||||
{template: template, directives: ALL_DIRECTIVES, pipes: ALL_PIPES}))
|
||||
return tcb
|
||||
.overrideView(
|
||||
comp,
|
||||
new ViewMetadata({template: template, directives: ALL_DIRECTIVES, pipes: ALL_PIPES}))
|
||||
.createFakeAsync(comp);
|
||||
}
|
||||
|
||||
function createComp(template: string, tcb: TestComponentBuilder,
|
||||
comp: Type = null): DebugElement {
|
||||
function createComp(
|
||||
template: string, tcb: TestComponentBuilder, comp: Type = null): DebugElement {
|
||||
var fixture = createCompFixture(template, tcb, comp);
|
||||
fixture.detectChanges();
|
||||
return fixture.debugElement;
|
||||
}
|
||||
|
||||
describe("View Injector", () => {
|
||||
describe('View Injector', () => {
|
||||
// On CJS fakeAsync is not supported...
|
||||
if (!getDOM().supportsDOMEvents()) return;
|
||||
|
||||
beforeEachProviders(() => [{provide: "appService", useValue: 'appService'}]);
|
||||
beforeEachProviders(() => [{provide: 'appService', useValue: 'appService'}]);
|
||||
|
||||
beforeEach(inject([TestComponentBuilder], (_tcb: TestComponentBuilder) => { tcb = _tcb; }));
|
||||
|
||||
describe("injection", () => {
|
||||
it("should instantiate directives that have no dependencies", fakeAsync(() => {
|
||||
describe('injection', () => {
|
||||
it('should instantiate directives that have no dependencies', fakeAsync(() => {
|
||||
var el = createComp('<div simpleDirective>', tcb);
|
||||
expect(el.children[0].inject(SimpleDirective)).toBeAnInstanceOf(SimpleDirective);
|
||||
}));
|
||||
|
||||
it("should instantiate directives that depend on another directive", fakeAsync(() => {
|
||||
it('should instantiate directives that depend on another directive', fakeAsync(() => {
|
||||
var el = createComp('<div simpleDirective needsDirective>', tcb);
|
||||
|
||||
var d = el.children[0].inject(NeedsDirective);
|
||||
@ -308,7 +280,7 @@ export function main() {
|
||||
|
||||
it('should support useValue with different values', fakeAsync(() => {
|
||||
var el = createComp('', tcb.overrideProviders(TestComp, [
|
||||
{provide:'numLiteral', useValue: 0},
|
||||
{provide: 'numLiteral', useValue: 0},
|
||||
{provide: 'boolLiteral', useValue: true},
|
||||
{provide: 'strLiteral', useValue: 'a'},
|
||||
{provide: 'null', useValue: null},
|
||||
@ -327,73 +299,74 @@ export function main() {
|
||||
expect(el.inject('nested')).toEqual([{'a': [1]}, new TestValue('b')]);
|
||||
}));
|
||||
|
||||
it("should instantiate providers that have dependencies with SkipSelf", fakeAsync(() => {
|
||||
var el = createComp('<div simpleDirective><span someOtherDirective></span></div>',
|
||||
tcb.overrideProviders(
|
||||
SimpleDirective,
|
||||
[{provide: 'injectable1', useValue: 'injectable1'}])
|
||||
.overrideProviders(SomeOtherDirective, [
|
||||
{provide: 'injectable1', useValue: 'new-injectable1'},
|
||||
{
|
||||
provide: 'injectable2',
|
||||
useFactory: (val: any /** TODO #9100 */) => `${val}-injectable2`,
|
||||
deps: [
|
||||
[
|
||||
new InjectMetadata('injectable1'),
|
||||
new SkipSelfMetadata()
|
||||
]
|
||||
]
|
||||
}
|
||||
]));
|
||||
it('should instantiate providers that have dependencies with SkipSelf', fakeAsync(() => {
|
||||
var el = createComp(
|
||||
'<div simpleDirective><span someOtherDirective></span></div>',
|
||||
tcb.overrideProviders(
|
||||
SimpleDirective, [{provide: 'injectable1', useValue: 'injectable1'}])
|
||||
.overrideProviders(SomeOtherDirective, [
|
||||
{provide: 'injectable1', useValue: 'new-injectable1'}, {
|
||||
provide: 'injectable2',
|
||||
useFactory: (val: any /** TODO #9100 */) => `${val}-injectable2`,
|
||||
deps: [[new InjectMetadata('injectable1'), new SkipSelfMetadata()]]
|
||||
}
|
||||
]));
|
||||
expect(el.children[0].children[0].inject('injectable2'))
|
||||
.toEqual('injectable1-injectable2');
|
||||
}));
|
||||
|
||||
it("should instantiate providers that have dependencies", fakeAsync(() => {
|
||||
it('should instantiate providers that have dependencies', fakeAsync(() => {
|
||||
var providers = [
|
||||
{provide: 'injectable1', useValue: 'injectable1'},
|
||||
{provide: 'injectable2', useFactory: (val: any /** TODO #9100 */) => `${val}-injectable2`, deps: ['injectable1']}
|
||||
{provide: 'injectable1', useValue: 'injectable1'}, {
|
||||
provide: 'injectable2',
|
||||
useFactory: (val: any /** TODO #9100 */) => `${val}-injectable2`,
|
||||
deps: ['injectable1']
|
||||
}
|
||||
];
|
||||
var el = createComp('<div simpleDirective></div>',
|
||||
tcb.overrideProviders(SimpleDirective, providers));
|
||||
var el = createComp(
|
||||
'<div simpleDirective></div>', tcb.overrideProviders(SimpleDirective, providers));
|
||||
expect(el.children[0].inject('injectable2')).toEqual('injectable1-injectable2');
|
||||
}));
|
||||
|
||||
it("should instantiate viewProviders that have dependencies", fakeAsync(() => {
|
||||
it('should instantiate viewProviders that have dependencies', fakeAsync(() => {
|
||||
var viewProviders = [
|
||||
{provide: 'injectable1', useValue: 'injectable1'},
|
||||
{provide: 'injectable2', useFactory: (val: any /** TODO #9100 */) => `${val}-injectable2`, deps: ['injectable1']}
|
||||
{provide: 'injectable1', useValue: 'injectable1'}, {
|
||||
provide: 'injectable2',
|
||||
useFactory: (val: any /** TODO #9100 */) => `${val}-injectable2`,
|
||||
deps: ['injectable1']
|
||||
}
|
||||
];
|
||||
|
||||
var el = createComp('<div simpleComponent></div>',
|
||||
tcb.overrideViewProviders(SimpleComponent, viewProviders));
|
||||
var el = createComp(
|
||||
'<div simpleComponent></div>',
|
||||
tcb.overrideViewProviders(SimpleComponent, viewProviders));
|
||||
expect(el.children[0].inject('injectable2')).toEqual('injectable1-injectable2');
|
||||
}));
|
||||
|
||||
it("should instantiate components that depend on viewProviders providers", fakeAsync(() => {
|
||||
var el =
|
||||
createComp('<div needsServiceComponent></div>',
|
||||
tcb.overrideViewProviders(NeedsServiceComponent,
|
||||
[{provide: 'service', useValue: 'service'}]));
|
||||
it('should instantiate components that depend on viewProviders providers', fakeAsync(() => {
|
||||
var el = createComp(
|
||||
'<div needsServiceComponent></div>',
|
||||
tcb.overrideViewProviders(
|
||||
NeedsServiceComponent, [{provide: 'service', useValue: 'service'}]));
|
||||
expect(el.children[0].inject(NeedsServiceComponent).service).toEqual('service');
|
||||
}));
|
||||
|
||||
it("should instantiate multi providers", fakeAsync(() => {
|
||||
it('should instantiate multi providers', fakeAsync(() => {
|
||||
var providers = [
|
||||
{provide: 'injectable1', useValue: 'injectable11', multi: true},
|
||||
{provide: 'injectable1', useValue: 'injectable12', multi: true}
|
||||
];
|
||||
var el = createComp('<div simpleDirective></div>',
|
||||
tcb.overrideProviders(SimpleDirective, providers));
|
||||
var el = createComp(
|
||||
'<div simpleDirective></div>', tcb.overrideProviders(SimpleDirective, providers));
|
||||
expect(el.children[0].inject('injectable1')).toEqual(['injectable11', 'injectable12']);
|
||||
}));
|
||||
|
||||
it("should instantiate providers lazily", fakeAsync(() => {
|
||||
it('should instantiate providers lazily', fakeAsync(() => {
|
||||
var created = false;
|
||||
var el = createComp(
|
||||
'<div simpleDirective></div>',
|
||||
tcb.overrideProviders(SimpleDirective,
|
||||
[{provide: 'service', useFactory: () => created = true}]));
|
||||
tcb.overrideProviders(
|
||||
SimpleDirective, [{provide: 'service', useFactory: () => created = true}]));
|
||||
|
||||
expect(created).toBe(false);
|
||||
|
||||
@ -402,12 +375,12 @@ export function main() {
|
||||
expect(created).toBe(true);
|
||||
}));
|
||||
|
||||
it("should instantiate view providers lazily", fakeAsync(() => {
|
||||
it('should instantiate view providers lazily', fakeAsync(() => {
|
||||
var created = false;
|
||||
var el = createComp(
|
||||
'<div simpleComponent></div>',
|
||||
tcb.overrideViewProviders(SimpleComponent,
|
||||
[{provide: 'service', useFactory: () => created = true}]));
|
||||
tcb.overrideViewProviders(
|
||||
SimpleComponent, [{provide: 'service', useFactory: () => created = true}]));
|
||||
|
||||
expect(created).toBe(false);
|
||||
|
||||
@ -416,107 +389,111 @@ export function main() {
|
||||
expect(created).toBe(true);
|
||||
}));
|
||||
|
||||
it("should not instantiate other directives that depend on viewProviders providers",
|
||||
it('should not instantiate other directives that depend on viewProviders providers',
|
||||
fakeAsync(() => {
|
||||
expect(() =>
|
||||
createComp('<div simpleComponent needsService></div>',
|
||||
tcb.overrideViewProviders(
|
||||
SimpleComponent, [{provide: "service", useValue: "service"}])))
|
||||
expect(
|
||||
() => createComp(
|
||||
'<div simpleComponent needsService></div>',
|
||||
tcb.overrideViewProviders(
|
||||
SimpleComponent, [{provide: 'service', useValue: 'service'}])))
|
||||
.toThrowError(containsRegexp(`No provider for service!`));
|
||||
}));
|
||||
|
||||
it("should instantiate directives that depend on providers of other directives",
|
||||
it('should instantiate directives that depend on providers of other directives',
|
||||
fakeAsync(() => {
|
||||
var el =
|
||||
createComp('<div simpleDirective><div needsService></div></div>',
|
||||
tcb.overrideProviders(SimpleDirective,
|
||||
[{provide: 'service', useValue: 'parentService'}]));
|
||||
var el = createComp(
|
||||
'<div simpleDirective><div needsService></div></div>',
|
||||
tcb.overrideProviders(
|
||||
SimpleDirective, [{provide: 'service', useValue: 'parentService'}]));
|
||||
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('parentService');
|
||||
}));
|
||||
|
||||
it("should instantiate directives that depend on providers in a parent view",
|
||||
it('should instantiate directives that depend on providers in a parent view',
|
||||
fakeAsync(() => {
|
||||
var el = createComp(
|
||||
'<div simpleDirective><template [ngIf]="true"><div *ngIf="true" needsService></div></template></div>',
|
||||
tcb.overrideProviders(SimpleDirective,
|
||||
[{provide: 'service', useValue: 'parentService'}]));
|
||||
tcb.overrideProviders(
|
||||
SimpleDirective, [{provide: 'service', useValue: 'parentService'}]));
|
||||
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('parentService');
|
||||
}));
|
||||
|
||||
it("should instantiate directives that depend on providers of a component", fakeAsync(() => {
|
||||
var el =
|
||||
createComp('<div simpleComponent></div>',
|
||||
tcb.overrideTemplate(SimpleComponent, '<div needsService></div>')
|
||||
.overrideProviders(SimpleComponent,
|
||||
[{provide: 'service', useValue: 'hostService'}]));
|
||||
it('should instantiate directives that depend on providers of a component', fakeAsync(() => {
|
||||
var el = createComp(
|
||||
'<div simpleComponent></div>',
|
||||
tcb.overrideTemplate(SimpleComponent, '<div needsService></div>')
|
||||
.overrideProviders(
|
||||
SimpleComponent, [{provide: 'service', useValue: 'hostService'}]));
|
||||
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
|
||||
}));
|
||||
|
||||
it("should instantiate directives that depend on view providers of a component",
|
||||
it('should instantiate directives that depend on view providers of a component',
|
||||
fakeAsync(() => {
|
||||
var el = createComp(
|
||||
'<div simpleComponent></div>',
|
||||
tcb.overrideTemplate(SimpleComponent, '<div needsService></div>')
|
||||
.overrideViewProviders(SimpleComponent,
|
||||
[{provide: 'service', useValue: 'hostService'}]));
|
||||
.overrideViewProviders(
|
||||
SimpleComponent, [{provide: 'service', useValue: 'hostService'}]));
|
||||
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
|
||||
}));
|
||||
|
||||
it("should instantiate directives in a root embedded view that depend on view providers of a component",
|
||||
it('should instantiate directives in a root embedded view that depend on view providers of a component',
|
||||
fakeAsync(() => {
|
||||
var el = createComp(
|
||||
'<div simpleComponent></div>',
|
||||
tcb.overrideTemplate(SimpleComponent, '<div *ngIf="true" needsService></div>')
|
||||
.overrideViewProviders(SimpleComponent,
|
||||
[{provide: 'service', useValue: 'hostService'}]));
|
||||
.overrideViewProviders(
|
||||
SimpleComponent, [{provide: 'service', useValue: 'hostService'}]));
|
||||
expect(el.children[0].children[0].inject(NeedsService).service).toEqual('hostService');
|
||||
}));
|
||||
|
||||
it("should instantiate directives that depend on instances in the app injector",
|
||||
it('should instantiate directives that depend on instances in the app injector',
|
||||
fakeAsync(() => {
|
||||
var el = createComp('<div needsAppService></div>', tcb);
|
||||
expect(el.children[0].inject(NeedsAppService).service).toEqual('appService');
|
||||
}));
|
||||
|
||||
it("should not instantiate a directive with cyclic dependencies", fakeAsync(() => {
|
||||
it('should not instantiate a directive with cyclic dependencies', fakeAsync(() => {
|
||||
expect(() => createComp('<div cycleDirective></div>', tcb))
|
||||
.toThrowError(
|
||||
'Template parse errors:\nCannot instantiate cyclic dependency! CycleDirective ("[ERROR ->]<div cycleDirective></div>"): TestComp@0:0');
|
||||
}));
|
||||
|
||||
it("should not instantiate a directive in a view that has a host dependency on providers" +
|
||||
" of the component",
|
||||
it('should not instantiate a directive in a view that has a host dependency on providers' +
|
||||
' of the component',
|
||||
fakeAsync(() => {
|
||||
expect(() => createComp(
|
||||
'<div simpleComponent></div>',
|
||||
tcb.overrideProviders(SimpleComponent,
|
||||
[{provide: 'service', useValue: 'hostService'}])
|
||||
.overrideTemplate(SimpleComponent, '<div needsServiceFromHost><div>')))
|
||||
expect(
|
||||
() => createComp(
|
||||
'<div simpleComponent></div>',
|
||||
tcb.overrideProviders(
|
||||
SimpleComponent, [{provide: 'service', useValue: 'hostService'}])
|
||||
.overrideTemplate(SimpleComponent, '<div needsServiceFromHost><div>')))
|
||||
.toThrowError(
|
||||
`Template parse errors:\nNo provider for service ("[ERROR ->]<div needsServiceFromHost><div>"): SimpleComponent@0:0`);
|
||||
}));
|
||||
|
||||
it("should not instantiate a directive in a view that has a host dependency on providers" +
|
||||
" of a decorator directive",
|
||||
it('should not instantiate a directive in a view that has a host dependency on providers' +
|
||||
' of a decorator directive',
|
||||
fakeAsync(() => {
|
||||
expect(() => createComp(
|
||||
'<div simpleComponent someOtherDirective></div>',
|
||||
tcb.overrideProviders(SomeOtherDirective,
|
||||
[{provide: 'service', useValue: 'hostService'}])
|
||||
.overrideTemplate(SimpleComponent, '<div needsServiceFromHost><div>')))
|
||||
expect(
|
||||
() => createComp(
|
||||
'<div simpleComponent someOtherDirective></div>',
|
||||
tcb.overrideProviders(
|
||||
SomeOtherDirective, [{provide: 'service', useValue: 'hostService'}])
|
||||
.overrideTemplate(SimpleComponent, '<div needsServiceFromHost><div>')))
|
||||
.toThrowError(
|
||||
`Template parse errors:\nNo provider for service ("[ERROR ->]<div needsServiceFromHost><div>"): SimpleComponent@0:0`);
|
||||
}));
|
||||
|
||||
it("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 self dependency on a parent directive',
|
||||
fakeAsync(() => {
|
||||
expect(() => createComp('<div simpleDirective><div needsDirectiveFromSelf></div></div>',
|
||||
tcb))
|
||||
expect(
|
||||
() =>
|
||||
createComp('<div simpleDirective><div needsDirectiveFromSelf></div></div>', tcb))
|
||||
.toThrowError(
|
||||
`Template parse errors:\nNo provider for SimpleDirective ("<div simpleDirective>[ERROR ->]<div needsDirectiveFromSelf></div></div>"): TestComp@0:21`);
|
||||
}));
|
||||
|
||||
it("should instantiate directives that depend on other directives", fakeAsync(() => {
|
||||
it('should instantiate directives that depend on other directives', fakeAsync(() => {
|
||||
var el = createComp('<div simpleDirective><div needsDirective></div></div>', tcb);
|
||||
var d = el.children[0].children[0].inject(NeedsDirective);
|
||||
|
||||
@ -524,18 +501,18 @@ export function main() {
|
||||
expect(d.dependency).toBeAnInstanceOf(SimpleDirective);
|
||||
}));
|
||||
|
||||
it("should throw when a dependency cannot be resolved", fakeAsync(() => {
|
||||
it('should throw when a dependency cannot be resolved', fakeAsync(() => {
|
||||
expect(() => createComp('<div needsService></div>', tcb))
|
||||
.toThrowError(containsRegexp(`No provider for service!`));
|
||||
}));
|
||||
|
||||
it("should inject null when an optional dependency cannot be resolved", fakeAsync(() => {
|
||||
it('should inject null when an optional dependency cannot be resolved', fakeAsync(() => {
|
||||
var el = createComp('<div optionallyNeedsDirective></div>', tcb);
|
||||
var d = el.children[0].inject(OptionallyNeedsDirective);
|
||||
expect(d.dependency).toEqual(null);
|
||||
}));
|
||||
|
||||
it("should instantiate directives that depends on the host component", fakeAsync(() => {
|
||||
it('should instantiate directives that depends on the host component', fakeAsync(() => {
|
||||
var el = createComp(
|
||||
'<div simpleComponent></div>',
|
||||
tcb.overrideTemplate(SimpleComponent, '<div needsComponentFromHost></div>'));
|
||||
@ -543,17 +520,18 @@ export function main() {
|
||||
expect(d.dependency).toBeAnInstanceOf(SimpleComponent);
|
||||
}));
|
||||
|
||||
it("should instantiate host views for components that have a @Host dependency ",
|
||||
it('should instantiate host views for components that have a @Host dependency ',
|
||||
fakeAsync(() => {
|
||||
var el = createComp('', tcb, NeedsHostAppService);
|
||||
expect(el.componentInstance.service).toEqual('appService');
|
||||
}));
|
||||
|
||||
it("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',
|
||||
fakeAsync(() => {
|
||||
expect(() => createComp(
|
||||
'<div simpleComponent simpleDirective></div>',
|
||||
tcb.overrideTemplate(SimpleComponent, '<div needsDirectiveFromHost></div>')))
|
||||
expect(
|
||||
() => createComp(
|
||||
'<div simpleComponent simpleDirective></div>',
|
||||
tcb.overrideTemplate(SimpleComponent, '<div needsDirectiveFromHost></div>')))
|
||||
.toThrowError(
|
||||
`Template parse errors:\nNo provider for SimpleDirective ("[ERROR ->]<div needsDirectiveFromHost></div>"): SimpleComponent@0:0`);
|
||||
}));
|
||||
@ -577,14 +555,14 @@ export function main() {
|
||||
}));
|
||||
});
|
||||
|
||||
describe("refs", () => {
|
||||
it("should inject ElementRef", fakeAsync(() => {
|
||||
describe('refs', () => {
|
||||
it('should inject ElementRef', fakeAsync(() => {
|
||||
var el = createComp('<div needsElementRef></div>', tcb);
|
||||
expect(el.children[0].inject(NeedsElementRef).elementRef.nativeElement)
|
||||
.toBe(el.children[0].nativeElement);
|
||||
}));
|
||||
|
||||
it("should inject ChangeDetectorRef of the component's view into the component via a proxy",
|
||||
it('should inject ChangeDetectorRef of the component\'s view into the component via a proxy',
|
||||
fakeAsync(() => {
|
||||
var cf = createCompFixture('<div componentNeedsChangeDetectorRef></div>', tcb);
|
||||
cf.detectChanges();
|
||||
@ -598,7 +576,7 @@ export function main() {
|
||||
expect(compEl.nativeElement).toHaveText('1');
|
||||
}));
|
||||
|
||||
it("should inject ChangeDetectorRef of the containing component into directives",
|
||||
it('should inject ChangeDetectorRef of the containing component into directives',
|
||||
fakeAsync(() => {
|
||||
var cf = createCompFixture(
|
||||
'<div componentNeedsChangeDetectorRef></div>',
|
||||
@ -627,13 +605,13 @@ export function main() {
|
||||
.toBe(el.children[0].nativeElement);
|
||||
}));
|
||||
|
||||
it("should inject TemplateRef", fakeAsync(() => {
|
||||
it('should inject TemplateRef', fakeAsync(() => {
|
||||
var el = createComp('<template needsViewContainerRef needsTemplateRef></template>', tcb);
|
||||
expect(el.childNodes[0].inject(NeedsTemplateRef).templateRef.elementRef)
|
||||
.toEqual(el.childNodes[0].inject(NeedsViewContainerRef).viewContainer.element);
|
||||
}));
|
||||
|
||||
it("should throw if there is no TemplateRef", fakeAsync(() => {
|
||||
it('should throw if there is no TemplateRef', fakeAsync(() => {
|
||||
expect(() => createComp('<div needsTemplateRef></div>', tcb))
|
||||
.toThrowError(containsRegexp(`No provider for TemplateRef!`));
|
||||
}));
|
||||
|
Reference in New Issue
Block a user