chore(tests): enable lint, make it green. (#10224)

This commit is contained in:
Victor Berchet
2016-07-21 17:12:00 -07:00
committed by GitHub
parent 27b87ef535
commit 00aa7a76b6
106 changed files with 1599 additions and 1634 deletions

View File

@ -1,5 +1,11 @@
import {LowerCasePipe, NgIf} from '@angular/common';
import {CompilerConfig} from '@angular/compiler';
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {ANALYZE_FOR_PRECOMPILE, AppModule, AppModuleMetadata, Compiler, Component, ComponentFactoryResolver, ComponentRef, ComponentResolver, DebugElement, Directive, Host, Inject, Injectable, Injector, Input, OpaqueToken, Optional, Pipe, Provider, ReflectiveInjector, SelfMetadata, SkipSelf, SkipSelfMetadata, forwardRef, getDebugNode, provide} from '@angular/core';
import {ComponentFixture, configureCompiler} from '@angular/core/testing';
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';

View File

@ -12,8 +12,7 @@ import {TEST_COMPILER_PROVIDERS} from '@angular/compiler/test/test_bindings';
import {MockSchemaRegistry} from '@angular/compiler/testing';
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, DoCheck, Injectable, Input, OnChanges, OnDestroy, OnInit, Output, Pipe, PipeTransform, RenderComponentType, Renderer, RootRenderer, SimpleChange, SimpleChanges, TemplateRef, ViewContainerRef, ViewMetadata, WrappedValue, forwardRef} from '@angular/core';
import {DebugDomRenderer} from '@angular/core/src/debug/debug_renderer';
import {TestComponentBuilder} from '@angular/core/testing';
import {ComponentFixture, configureCompiler, configureModule, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
import {ComponentFixture, TestComponentBuilder, configureCompiler, configureModule, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {By} from '@angular/platform-browser/src/dom/debug/by';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
@ -597,8 +596,9 @@ 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!'));
expect(() => {
_bindSimpleProp('(event)="$event=1"');
}).toThrowError(new RegExp('Cannot assign to a reference or variable!'));
}));
it('should support short-circuiting', fakeAsync(() => {
@ -625,7 +625,7 @@ 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>')
'<div testDirective [a]="42" ref-dir="testDirective" [someProp]="dir.a"></div>');
ctx.detectChanges(false);
expect(renderLog.loggedValues).toEqual([42]);
}));
@ -1479,7 +1479,7 @@ class Address {
set zipcode(v) { this._zipcode = v; }
toString(): string { return isBlank(this.city) ? '-' : this.city }
toString(): string { return this.city || '-'; }
}
@Component({selector: 'root'})

View File

@ -6,12 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
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 {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing';
import {Predicate} from '../../src/facade/collection';
import {Injector, OnDestroy, DebugElement, Type, ViewContainerRef, ViewChild} from '@angular/core';
import {Component, ViewMetadata} from '@angular/core/src/metadata';
import {Injector, DebugElement, Type, ViewContainerRef, ViewChild} from '@angular/core';
import {Component} from '@angular/core/src/metadata';
import {DynamicComponentLoader} from '@angular/core/src/linker/dynamic_component_loader';
import {ElementRef} from '@angular/core/src/linker/element_ref';
import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens';

View File

@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {fakeAsync, tick, ComponentFixture, configureCompiler, configureModule, TestComponentBuilder} from '@angular/core/testing';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {isPresent, stringify, isBlank,} from '../../src/facade/lang';
import {BaseException} from '../../src/facade/exceptions';
@ -34,19 +33,14 @@ import {ElementRef} from '@angular/core/src/linker/element_ref';
import {TemplateRef, TemplateRef_} from '@angular/core/src/linker/template_ref';
import {Renderer} from '@angular/core/src/render';
import {IS_DART} from '../../src/facade/lang';
import {el, dispatchEvent} from '@angular/platform-browser/testing/browser_util';
const ANCHOR_ELEMENT = /*@ts2dart_const*/ new OpaqueToken('AnchorElement');
export function main() {
if (IS_DART) {
declareTests({useJit: false});
} else {
describe('jit', () => { declareTests({useJit: true}); });
describe('jit', () => { declareTests({useJit: true}); });
describe('no jit', () => { declareTests({useJit: false}); });
}
describe('no jit', () => { declareTests({useJit: false}); });
}
function declareTests({useJit}: {useJit: boolean}) {
@ -583,18 +577,18 @@ function declareTests({useJit}: {useJit: boolean}) {
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: '<p><child-cmp ref-alice></child-cmp></p>',
directives: [ChildComp]
}))
tcb.overrideView(MyComp, new ViewMetadata({
template: '<p><child-cmp ref-alice></child-cmp></p>',
directives: [ChildComp]
}))
.createAsync(MyComp)
.then((fixture) => {
expect(fixture.debugElement.children[0].children[0].references['alice'])
.toBeAnInstanceOf(ChildComp);
.createAsync(MyComp)
.then((fixture) => {
expect(fixture.debugElement.children[0].children[0].references['alice'])
.toBeAnInstanceOf(ChildComp);
async.done();
})}));
async.done();
});
}));
it('should assign a directive to a ref-',
inject(
@ -604,7 +598,6 @@ function declareTests({useJit}: {useJit: boolean}) {
template: '<div><div export-dir #localdir="dir"></div></div>',
directives: [ExportDir]
}))
.createAsync(MyComp)
.then((fixture) => {
expect(fixture.debugElement.children[0].children[0].references['localdir'])
@ -618,97 +611,96 @@ function declareTests({useJit}: {useJit: boolean}) {
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
MyComp, new ViewMetadata({
template:
'<template [ngIf]="true">{{alice.ctxProp}}</template>|{{alice.ctxProp}}|<child-cmp ref-alice></child-cmp>',
directives: [ChildComp, NgIf]
}))
tcb.overrideView(
MyComp, new ViewMetadata({
template:
'<template [ngIf]="true">{{alice.ctxProp}}</template>|{{alice.ctxProp}}|<child-cmp ref-alice></child-cmp>',
directives: [ChildComp, NgIf]
}))
.createAsync(MyComp)
.then((fixture) => {
fixture.detectChanges();
.createAsync(MyComp)
.then((fixture) => {
fixture.detectChanges();
expect(fixture.debugElement.nativeElement).toHaveText('hello|hello|hello');
async.done();
})}));
expect(fixture.debugElement.nativeElement).toHaveText('hello|hello|hello');
async.done();
});
}));
it('should assign two component instances each with a ref-',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
MyComp, new ViewMetadata({
template:
'<p><child-cmp ref-alice></child-cmp><child-cmp ref-bob></child-cmp></p>',
directives: [ChildComp]
}))
tcb.overrideView(
MyComp, new ViewMetadata({
template:
'<p><child-cmp ref-alice></child-cmp><child-cmp ref-bob></child-cmp></p>',
directives: [ChildComp]
}))
.createAsync(MyComp)
.then((fixture) => {
var pEl = fixture.debugElement.children[0];
.createAsync(MyComp)
.then((fixture) => {
var pEl = fixture.debugElement.children[0];
var alice = pEl.children[0].references['alice'];
var bob = pEl.children[1].references['bob'];
expect(alice).toBeAnInstanceOf(ChildComp);
expect(bob).toBeAnInstanceOf(ChildComp);
expect(alice).not.toBe(bob);
var alice = pEl.children[0].references['alice'];
var bob = pEl.children[1].references['bob'];
expect(alice).toBeAnInstanceOf(ChildComp);
expect(bob).toBeAnInstanceOf(ChildComp);
expect(alice).not.toBe(bob);
async.done();
})}));
async.done();
});
}));
it('should assign the component instance to a ref- with shorthand syntax',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: '<child-cmp #alice></child-cmp>',
directives: [ChildComp]
}))
tcb.overrideView(
MyComp,
new ViewMetadata(
{template: '<child-cmp #alice></child-cmp>', directives: [ChildComp]}))
.createAsync(MyComp)
.then((fixture) => {
.createAsync(MyComp)
.then((fixture) => {
expect(fixture.debugElement.children[0].references['alice'])
.toBeAnInstanceOf(ChildComp);
expect(fixture.debugElement.children[0].references['alice'])
.toBeAnInstanceOf(ChildComp);
async.done();
})}));
async.done();
});
}));
it('should assign the element instance to a user-defined variable',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
MyComp, new ViewMetadata(
{template: '<div><div ref-alice><i>Hello</i></div></div>'}))
tcb.overrideView(
MyComp, new ViewMetadata(
{template: '<div><div ref-alice><i>Hello</i></div></div>'}))
.createAsync(MyComp)
.then((fixture) => {
.createAsync(MyComp)
.then((fixture) => {
var value = fixture.debugElement.children[0].children[0].references['alice'];
expect(value).not.toBe(null);
expect(value.tagName.toLowerCase()).toEqual('div');
var value =
fixture.debugElement.children[0].children[0].references['alice'];
expect(value).not.toBe(null);
expect(value.tagName.toLowerCase()).toEqual('div');
async.done();
})}));
async.done();
});
}));
it('should assign the TemplateRef to a user-defined variable',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
MyComp, new ViewMetadata({template: '<template ref-alice></template>'}))
tcb.overrideView(
MyComp, new ViewMetadata({template: '<template ref-alice></template>'}))
.createAsync(MyComp)
.then((fixture) => {
.createAsync(MyComp)
.then((fixture) => {
var value = fixture.debugElement.childNodes[0].references['alice'];
expect(value).toBeAnInstanceOf(TemplateRef_);
var value = fixture.debugElement.childNodes[0].references['alice'];
expect(value).toBeAnInstanceOf(TemplateRef_);
async.done();
})}));
async.done();
});
}));
it('should preserve case',
inject(
@ -718,7 +710,6 @@ function declareTests({useJit}: {useJit: boolean}) {
template: '<p><child-cmp ref-superAlice></child-cmp></p>',
directives: [ChildComp]
}))
.createAsync(MyComp)
.then((fixture) => {
expect(fixture.debugElement.children[0].children[0].references['superAlice'])
@ -740,7 +731,6 @@ function declareTests({useJit}: {useJit: boolean}) {
'<template ngFor [ngForOf]="[1]" let-i><child-cmp-no-template #cmp></child-cmp-no-template>{{i}}-{{cmp.ctxProp}}</template>',
directives: [ChildCompNoTemplate, NgFor]
}))
.createAsync(MyComp)
.then((fixture) => {
fixture.detectChanges();
@ -760,53 +750,53 @@ function declareTests({useJit}: {useJit: boolean}) {
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: '<push-cmp-with-ref #cmp></push-cmp-with-ref>',
directives: [[[PushCmpWithRef]]]
}))
tcb.overrideView(MyComp, new ViewMetadata({
template: '<push-cmp-with-ref #cmp></push-cmp-with-ref>',
directives: [[[PushCmpWithRef]]]
}))
.createAsync(MyComp)
.then((fixture) => {
.createAsync(MyComp)
.then((fixture) => {
var cmp = fixture.debugElement.children[0].references['cmp'];
var cmp = fixture.debugElement.children[0].references['cmp'];
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(1);
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(1);
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(1);
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(1);
cmp.propagate();
cmp.propagate();
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(2);
async.done();
})}));
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(2);
async.done();
});
}));
it('should be checked when its bindings got updated',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: '<push-cmp [prop]="ctxProp" #cmp></push-cmp>',
directives: [[[PushCmp]]]
}))
tcb.overrideView(MyComp, new ViewMetadata({
template: '<push-cmp [prop]="ctxProp" #cmp></push-cmp>',
directives: [[[PushCmp]]]
}))
.createAsync(MyComp)
.then((fixture) => {
var cmp = fixture.debugElement.children[0].references['cmp'];
.createAsync(MyComp)
.then((fixture) => {
var cmp = fixture.debugElement.children[0].references['cmp'];
fixture.debugElement.componentInstance.ctxProp = 'one';
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(1);
fixture.debugElement.componentInstance.ctxProp = 'one';
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(1);
fixture.debugElement.componentInstance.ctxProp = 'two';
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(2);
fixture.debugElement.componentInstance.ctxProp = 'two';
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(2);
async.done();
})}));
async.done();
});
}));
if (getDOM().supportsDOMEvents()) {
it('should allow to destroy a component from within a host event handler',
@ -835,69 +825,68 @@ function declareTests({useJit}: {useJit: boolean}) {
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: '<push-cmp [prop]="ctxProp" #cmp></push-cmp>',
directives: [[[PushCmp]]]
}))
tcb.overrideView(MyComp, new ViewMetadata({
template: '<push-cmp [prop]="ctxProp" #cmp></push-cmp>',
directives: [[[PushCmp]]]
}))
.createAsync(MyComp)
.then((fixture) => {
var cmpEl = fixture.debugElement.children[0];
var cmp = cmpEl.componentInstance;
fixture.detectChanges();
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(1);
.createAsync(MyComp)
.then((fixture) => {
var cmpEl = fixture.debugElement.children[0];
var cmp = cmpEl.componentInstance;
fixture.detectChanges();
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(1);
cmpEl.children[0].triggerEventHandler('click', <Event>{});
cmpEl.children[0].triggerEventHandler('click', <Event>{});
// regular element
fixture.detectChanges();
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(2);
// regular element
fixture.detectChanges();
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(2);
// element inside of an *ngIf
cmpEl.children[1].triggerEventHandler('click', <Event>{});
// element inside of an *ngIf
cmpEl.children[1].triggerEventHandler('click', <Event>{});
fixture.detectChanges();
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(3);
fixture.detectChanges();
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(3);
// element inside a nested component
cmpEl.children[2].children[0].triggerEventHandler('click', <Event>{});
// element inside a nested component
cmpEl.children[2].children[0].triggerEventHandler('click', <Event>{});
fixture.detectChanges();
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(4);
fixture.detectChanges();
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(4);
async.done();
})}));
async.done();
});
}));
it('should not affect updating properties on the component',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
MyComp, new ViewMetadata({
template:
'<push-cmp-with-ref [prop]="ctxProp" #cmp></push-cmp-with-ref>',
directives: [[[PushCmpWithRef]]]
}))
tcb.overrideView(
MyComp, new ViewMetadata({
template: '<push-cmp-with-ref [prop]="ctxProp" #cmp></push-cmp-with-ref>',
directives: [[[PushCmpWithRef]]]
}))
.createAsync(MyComp)
.then((fixture) => {
.createAsync(MyComp)
.then((fixture) => {
var cmp = fixture.debugElement.children[0].references['cmp'];
var cmp = fixture.debugElement.children[0].references['cmp'];
fixture.debugElement.componentInstance.ctxProp = 'one';
fixture.detectChanges();
expect(cmp.prop).toEqual('one');
fixture.debugElement.componentInstance.ctxProp = 'one';
fixture.detectChanges();
expect(cmp.prop).toEqual('one');
fixture.debugElement.componentInstance.ctxProp = 'two';
fixture.detectChanges();
expect(cmp.prop).toEqual('two');
fixture.debugElement.componentInstance.ctxProp = 'two';
fixture.detectChanges();
expect(cmp.prop).toEqual('two');
async.done();
})}));
async.done();
});
}));
if (getDOM().supportsDOMEvents()) {
it('should be checked when an async pipe requests a check',
@ -932,27 +921,28 @@ function declareTests({useJit}: {useJit: boolean}) {
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: `
tcb.overrideView(MyComp, new ViewMetadata({
template: `
<some-directive>
<p>
<cmp-with-host #child></cmp-with-host>
</p>
</some-directive>`,
directives: [SomeDirective, CompWithHost]
}))
directives: [SomeDirective, CompWithHost]
}))
.createAsync(MyComp)
.then((fixture) => {
.createAsync(MyComp)
.then((fixture) => {
var childComponent = fixture.debugElement.children[0]
.children[0]
.children[0]
.references['child'];
expect(childComponent.myHost).toBeAnInstanceOf(SomeDirective);
var childComponent = fixture.debugElement.children[0]
.children[0]
.children[0]
.references['child'];
expect(childComponent.myHost).toBeAnInstanceOf(SomeDirective);
async.done();
})}));
async.done();
});
}));
it('should create a component that injects an @Host through viewcontainer directive',
inject(
@ -989,7 +979,6 @@ function declareTests({useJit}: {useJit: boolean}) {
template: '<div emitter listener></div>',
directives: [DirectiveEmittingEvent, DirectiveListeningEvent]
}))
.createAsync(MyComp)
.then((fixture) => {
@ -1026,7 +1015,6 @@ function declareTests({useJit}: {useJit: boolean}) {
template: '<template emitter listener (event)="ctxProp=$event"></template>',
directives: [DirectiveEmittingEvent, DirectiveListeningEvent]
}))
.createAsync(MyComp)
.then((fixture) => {
@ -1057,7 +1045,6 @@ function declareTests({useJit}: {useJit: boolean}) {
template: '<div [(control)]="ctxProp" two-way></div>',
directives: [DirectiveWithTwoWayBinding]
}))
.createAsync(MyComp)
.then((fixture) => {
var tc = fixture.debugElement.children[0];
@ -1085,7 +1072,6 @@ function declareTests({useJit}: {useJit: boolean}) {
template: '<div listener></div>',
directives: [DirectiveListeningDomEvent]
}))
.createAsync(MyComp)
.then((fixture) => {
@ -1115,7 +1101,6 @@ function declareTests({useJit}: {useJit: boolean}) {
template: '<div listener></div>',
directives: [DirectiveListeningDomEvent]
}))
.createAsync(MyComp)
.then((fixture) => {
var tc = fixture.debugElement.children[0];
@ -1144,7 +1129,6 @@ function declareTests({useJit}: {useJit: boolean}) {
template: '<div update-host-attributes></div>',
directives: [DirectiveUpdatingHostAttributes]
}))
.createAsync(MyComp)
.then((fixture) => {
fixture.detectChanges();
@ -1165,7 +1149,6 @@ function declareTests({useJit}: {useJit: boolean}) {
template: '<div update-host-properties></div>',
directives: [DirectiveUpdatingHostProperties]
}))
.createAsync(MyComp)
.then((fixture) => {
var tc = fixture.debugElement.children[0];
@ -1195,7 +1178,6 @@ function declareTests({useJit}: {useJit: boolean}) {
DirectiveListeningDomEventPrevent, DirectiveListeningDomEventNoPrevent
]
}))
.createAsync(MyComp)
.then((fixture) => {
var dispatchedEvent = getDOM().createMouseEvent('click');
@ -1225,7 +1207,6 @@ function declareTests({useJit}: {useJit: boolean}) {
directives:
[NgIf, DirectiveListeningDomEvent, DirectiveListeningDomEventOther]
}))
.createAsync(MyComp)
.then((fixture) => {
globalCounter = 0;
@ -1269,7 +1250,6 @@ function declareTests({useJit}: {useJit: boolean}) {
template: '<div><dynamic-vp #dynamic></dynamic-vp></div>',
directives: [DynamicViewport]
}))
.createAsync(MyComp)
.then((fixture) => {
var tc = fixture.debugElement.children[0].children[0];
@ -1625,62 +1605,60 @@ function declareTests({useJit}: {useJit: boolean}) {
})));
}
if (!IS_DART) {
it('should report a meaningful error when a directive is undefined',
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
it('should report a meaningful error when a directive is undefined',
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
var undefinedValue: any = void(0);
var undefinedValue: any = void(0);
tcb = tcb.overrideView(
MyComp, new ViewMetadata({directives: [undefinedValue], template: ''}));
tcb = tcb.overrideView(
MyComp, new ViewMetadata({directives: [undefinedValue], template: ''}));
expect(() => tcb.createAsync(MyComp))
.toThrowError(
`Unexpected directive value 'undefined' on the View of component '${stringify(MyComp)}'`);
}));
}
expect(() => tcb.createAsync(MyComp))
.toThrowError(
`Unexpected directive value 'undefined' on the View of component '${stringify(MyComp)}'`);
}));
it('should specify a location of an error that happened during change detection (text)',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp, new ViewMetadata({template: '<div>{{a.b}}</div>'}))
.createAsync(MyComp)
.then((fixture) => {
expect(() => fixture.detectChanges()).toThrowError(/:0:5/);
async.done();
})}));
tcb.overrideView(MyComp, new ViewMetadata({template: '<div>{{a.b}}</div>'}))
.createAsync(MyComp)
.then((fixture) => {
expect(() => fixture.detectChanges()).toThrowError(/:0:5/);
async.done();
});
}));
it('should specify a location of an error that happened during change detection (element property)',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp, new ViewMetadata({template: '<div [title]="a.b"></div>'}))
.createAsync(MyComp)
.then((fixture) => {
expect(() => fixture.detectChanges()).toThrowError(/:0:5/);
async.done();
})}));
tcb.overrideView(MyComp, new ViewMetadata({template: '<div [title]="a.b"></div>'}))
.createAsync(MyComp)
.then((fixture) => {
expect(() => fixture.detectChanges()).toThrowError(/:0:5/);
async.done();
});
}));
it('should specify a location of an error that happened during change detection (directive property)',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: '<child-cmp [title]="a.b"></child-cmp>',
directives: [ChildComp]
}))
.createAsync(MyComp)
.then((fixture) => {
expect(() => fixture.detectChanges()).toThrowError(/:0:11/);
async.done();
})}));
tcb.overrideView(MyComp, new ViewMetadata({
template: '<child-cmp [title]="a.b"></child-cmp>',
directives: [ChildComp]
}))
.createAsync(MyComp)
.then((fixture) => {
expect(() => fixture.detectChanges()).toThrowError(/:0:11/);
async.done();
});
}));
});
it('should support imperative views',
@ -1725,34 +1703,32 @@ function declareTests({useJit}: {useJit: boolean}) {
}));
describe('Property bindings', () => {
if (!IS_DART) {
it('should throw on bindings to unknown properties',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb = tcb.overrideView(
MyComp, new ViewMetadata({template: '<div unknown="{{ctxProp}}"></div>'}))
it('should throw on bindings to unknown properties',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb = tcb.overrideView(
MyComp, new ViewMetadata({template: '<div unknown="{{ctxProp}}"></div>'}));
PromiseWrapper.catchError(tcb.createAsync(MyComp), (e) => {
expect(e.message).toEqual(
`Template parse errors:\nCan't bind to 'unknown' since it isn't a known native property ("<div [ERROR ->]unknown="{{ctxProp}}"></div>"): MyComp@0:5`);
async.done();
return null;
});
}));
PromiseWrapper.catchError(tcb.createAsync(MyComp), (e) => {
expect(e.message).toEqual(
`Template parse errors:\nCan't bind to 'unknown' since it isn't a known native property ("<div [ERROR ->]unknown="{{ctxProp}}"></div>"): MyComp@0:5`);
async.done();
return null;
});
}));
it('should not throw for property binding to a non-existing property when there is a matching directive property',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: '<div my-dir [elprop]="ctxProp"></div>',
directives: [MyDir]
}))
.createAsync(MyComp)
.then((val) => { async.done(); });
}));
}
it('should not throw for property binding to a non-existing property when there is a matching directive property',
inject(
[TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
tcb.overrideView(
MyComp,
new ViewMetadata(
{template: '<div my-dir [elprop]="ctxProp"></div>', directives: [MyDir]}))
.createAsync(MyComp)
.then((val) => { async.done(); });
}));
it('should not be created when there is a directive with the same property',
inject(
@ -1987,15 +1963,9 @@ function declareTests({useJit}: {useJit: boolean}) {
expect(getDOM().getProperty(<Element>use, 'namespaceURI'))
.toEqual('http://www.w3.org/2000/svg');
if (!IS_DART) {
var firstAttribute = getDOM().getProperty(<Element>use, 'attributes')[0];
expect(firstAttribute.name).toEqual('xlink:href');
expect(firstAttribute.namespaceURI)
.toEqual('http://www.w3.org/1999/xlink');
} else {
// For Dart where '_Attr' has no instance getter 'namespaceURI'
expect(getDOM().getOuterHTML(<HTMLElement>use)).toContain('xmlns:xlink');
}
var firstAttribute = getDOM().getProperty(<Element>use, 'attributes')[0];
expect(firstAttribute.name).toEqual('xlink:href');
expect(firstAttribute.namespaceURI).toEqual('http://www.w3.org/1999/xlink');
async.done();
});

View File

@ -6,14 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
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 {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {configureCompiler, TestComponentBuilder} from '@angular/core/testing';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {OpaqueToken, ViewMetadata, Component, Directive, AfterContentInit, AfterViewInit, QueryList, ContentChildren, ViewChildren, Input} from '@angular/core';
import {Component, Directive, AfterContentInit, AfterViewInit, QueryList, ContentChildren, ViewChildren, Input} from '@angular/core';
import {NgIf} from '@angular/common';
import {CompilerConfig} from '@angular/compiler';
import {el} from '@angular/platform-browser/testing/browser_util';
export function main() {
describe('jit', () => { declareTests({useJit: true}); });

View File

@ -6,12 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {TestComponentBuilder} from '@angular/core/testing';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {Component, ViewChild, ViewContainerRef, ComponentFactoryResolver, NoComponentFactoryError, ComponentRef, forwardRef, ANALYZE_FOR_PRECOMPILE} from '@angular/core';
import {CompilerConfig} from '@angular/compiler';
import {Component, ComponentFactoryResolver, NoComponentFactoryError, forwardRef, ANALYZE_FOR_PRECOMPILE} from '@angular/core';
export function main() {
describe('jit', () => { declareTests({useJit: true}); });

View File

@ -6,13 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
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 {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {ComponentFixture, TestComponentBuilder} from '@angular/core/testing';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {bind, provide, forwardRef, Component, Directive, ElementRef, TemplateRef, ViewContainerRef, ViewEncapsulation, ViewMetadata} from '@angular/core';
import {forwardRef, Component, Directive, ElementRef, TemplateRef, ViewContainerRef, ViewEncapsulation, ViewMetadata} from '@angular/core';
import {By,} from '@angular/platform-browser/src/dom/debug/by';
import {getAllDebugNodes} from '@angular/core/src/debug/debug_node';

View File

@ -6,16 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
import {TestComponentBuilder} from '@angular/core/testing';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {isPresent, stringify} from '../../src/facade/lang';
import {ObservableWrapper} from '../../src/facade/async';
import {Component, Directive, TemplateRef, Query, QueryList, ViewQuery, ContentChildren, ViewChildren, ContentChild, ViewChild, AfterContentInit, AfterViewInit, AfterContentChecked, AfterViewChecked} from '@angular/core';
import {asNativeElements, ViewContainerRef, Component, Directive, TemplateRef, Query, QueryList, ViewQuery, ContentChildren, ViewChildren, ContentChild, ViewChild, AfterContentInit, AfterViewInit, AfterContentChecked, AfterViewChecked} from '@angular/core';
import {NgIf, NgFor} from '@angular/common';
import {asNativeElements, ViewContainerRef} from '@angular/core';
export function main() {
describe('Query API', () => {
@ -303,9 +301,9 @@ export function main() {
expect(needsTpl.vc.createEmbeddedView(needsTpl.contentTpl).rootNodes[0])
.toHaveText('light');
expect(needsTpl.vc.createEmbeddedView(needsTpl.viewTpl).rootNodes[0])
.toHaveText('shadow')
.toHaveText('shadow');
async.done();
async.done();
});
}));
});
@ -833,6 +831,7 @@ class NeedsViewChildren implements AfterViewInit {
@Component({selector: 'needs-content-child', template: ''})
class NeedsContentChild implements AfterContentInit, AfterContentChecked {
/** @internal */
_child: TextDirective;
@ContentChild(TextDirective)
@ -862,6 +861,7 @@ class NeedsViewChild implements AfterViewInit,
AfterViewChecked {
shouldShow: boolean = true;
shouldShow2: boolean = false;
/** @internal */
_child: TextDirective;
@ViewChild(TextDirective)

View File

@ -6,12 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Component, provide} from '@angular/core';
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';
import {AsyncTestCompleter, afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {Console} from '../../src/console';
class DummyConsole implements Console {
@ -42,8 +40,8 @@ export function main() {
it('should throw when given a string',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
compiler.resolveComponent('someString').catch((e) => {
expect(e.message).toContain('Cannot resolve component using \'someString\'.')
async.done();
expect(e.message).toContain('Cannot resolve component using \'someString\'.');
async.done();
});
}));
});

View File

@ -6,24 +6,16 @@
* found in the LICENSE file at https://angular.io/license
*/
import {beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
import {configureCompiler, configureModule, TestComponentBuilder} from '@angular/core/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, forwardRef} from '@angular/core';
import {Component, Pipe, PipeTransform, ViewMetadata, OpaqueToken, Injector, forwardRef} from '@angular/core';
import {NgIf, NgClass} from '@angular/common';
import {CompilerConfig} from '@angular/compiler';
export function main() {
if (IS_DART) {
declareTests({useJit: false});
} else {
describe('jit', () => { declareTests({useJit: true}); });
describe('jit', () => { declareTests({useJit: true}); });
describe('no jit', () => { declareTests({useJit: false}); });
}
describe('no jit', () => { declareTests({useJit: false}); });
}
function declareTests({useJit}: {useJit: boolean}) {
@ -68,20 +60,18 @@ function declareTests({useJit}: {useJit: boolean}) {
});
}));
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();
});
}));
}
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();
});
}));
});
describe('providers', () => {

View File

@ -6,26 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ddescribe, describe, expect, inject, beforeEachProviders, beforeEach, afterEach, it,} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter} from '@angular/core/testing/testing_internal';
import {AsyncTestCompleter, ddescribe, describe, expect, inject, beforeEachProviders, beforeEach, afterEach, it,} from '@angular/core/testing/testing_internal';
import {configureCompiler, TestComponentBuilder} from '@angular/core/testing';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {provide, Injectable, OpaqueToken} from '@angular/core';
import {CompilerConfig} from '@angular/compiler';
import {Component, ViewMetadata} from '@angular/core/src/metadata';
import {IS_DART} from '../../src/facade/lang';
import {el} from '@angular/platform-browser/testing/browser_util';
import {Component} from '@angular/core/src/metadata';
import {DomSanitizationService} from '@angular/platform-browser/src/security/dom_sanitization_service';
export function main() {
if (IS_DART) {
declareTests({useJit: false});
} else {
describe('jit', () => { declareTests({useJit: true}); });
describe('jit', () => { declareTests({useJit: true}); });
describe('no jit', () => { declareTests({useJit: false}); });
}
describe('no jit', () => { declareTests({useJit: false}); });
}
@Component({selector: 'my-comp', template: '', directives: []})