mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build(linting): execute tslint in travis
execute tslint in travis ci build
- uses npm script until ng lint task is stable
- lints only the typescript in the src directory
- executes in before_script section of travis.yml to fail fast
chore(tslint): update no-unused-variable tslint rule
modify the no-unused-variable tslint rule to ignore
- ddescribe
- iit
style(button): resolves basic tslint errors
resolve the following tslint violations
- max-line-length
- whitespace
style(card): resolves basic tslint errors
resolve the following tslint violations
- max-line-length
style(progress-circle): resolves basic tslint errors
resolve the following tslint violations
- max-line-length
- whitespace
- eofline
- semicolon
style(sidenav): resolves basic tslint errors
resolve the following tslint violations
- no-inferrable-types
- max-line-length
- whitespace
- eofline
- semicolon
style(annotations): resolves basic tslint errors
resolve the following tslint violations
- semicolon
style(demo-app): resolves basic tslint errors
resolve the following tslint violations
- eofline
style(directives): resolves basic tslint errors
resolve the following tslint violations
- quotemark
style(sidenav): resolves unused variable tslint errors
remove the following unused imports
- Predicate
- PromiseWrapper
- TimerWrapper
remove the following unused variable
- let openPromise: Promise<void>
ignore rule no-unused-variable on the following functions
- closeModalSidenav_()
- isShowingBackdrop_()
- getMarginLeft_()
- getMarginRight_()
- getPositionLeft_()
- getPositionRight_()
style(progress-circle): resolves unused variable tslint errors
remove the following unused imports
- Attribute
- ElementRef
- ViewEncapsulation
style(button): resolves unused variable tslint errors
remove the following unused imports
- ComponentFixture
- beforeEachProviders
- provide
- DebugElement
- AsyncTestFn
ignore rule no-unused-variable on the following function
- testAsync()
style(one-of): resolves variable-name tslint errors
rename OneOf to oneOf (camelCase) in following files
- progress_circle.ts
- sidenav.ts
- one-of.ts
- dir.ts
style(test_injector): resolves variable tslint errors
remove the following unused import
- ExceptionHandler
ignore rule variable-name on the following variables
- _testInjector
- _providers
- _injector
- _instantiated
style(main): resolves variable tslint errors
remove the following unused imports
- HashLocationStrategy
- LocationStrategy
- provide
build(linting): update tslint version
Update to 3.5.0 to make user of ignore patterns
style(sidenav): remove individual tslint rule ignore statements
- remove all individual ignore statements for no-unused-variable on private class members
- add regex to no-unused-variable ignore-pattern
style(sidenav.spec): modify line break
- break after toEqual to improve readability
style(test_injector): resolves variable tslint errors
rename var to let
remove all individual ignore statements for variable-name
move _ to end of private var name
rename testInjector to testInjectorCache
- resolves no-shadowed-variable error in setBaseTestProviders()
- resolves no-shadowed-variable error in resetBaseTestProviders()
style(button.spec): remove unused testAsync function
- remove unused testAsync function
- remove now unused module imports
style(karma-test-shim): increase jasmine default timeout
increase jasmine.DEFAULT_TIMEOUT_INTERVAL from 2000 to 4000ms.
- Temporary resolution of Async callback timeouts in tests
style(button): fix whitespace
resolve whitespace issue in setClassList()
style(one-of): modified case of OneOf
- Fixed case for OneOf dec. factory
- Modified export in one-of.ts
Closes #134
This commit is contained in:
committed by
Jeremy Elbourn
parent
10c9aed401
commit
425db8aef5
+1
-1
@@ -53,6 +53,7 @@ before_script:
|
||||
- "export DISPLAY=:99.0"
|
||||
- "sh -e /etc/init.d/xvfb start"
|
||||
- mkdir -p $LOGS_DIR
|
||||
- npm run tslint
|
||||
|
||||
|
||||
script:
|
||||
@@ -62,4 +63,3 @@ cache:
|
||||
directories:
|
||||
- node_modules
|
||||
- $HOME/.pub-cache
|
||||
|
||||
|
||||
+2
-1
@@ -12,6 +12,7 @@
|
||||
"dartanalyzer": "cd dist/dart && pub install && cd ../.. && ts-node scripts/ci/dart_analyzer",
|
||||
"demo-app": "cd src && ng serve",
|
||||
"test": "karma start test/karma.conf.js",
|
||||
"tslint" : "tslint -c tslint.json 'src/**/*.ts'",
|
||||
"typings": "typings install --ambient"
|
||||
},
|
||||
"version": "2.0.0-alpha.0",
|
||||
@@ -53,7 +54,7 @@
|
||||
"symlink-or-copy": "^1.0.1",
|
||||
"ts-node": "^0.5.5",
|
||||
"ts2dart": "^0.7.27",
|
||||
"tslint": "^3.2.2",
|
||||
"tslint": "^3.5.0",
|
||||
"typescript": "^1.7.5",
|
||||
"typings": "^0.6.8",
|
||||
"which": "^1.2.4"
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import {
|
||||
inject,
|
||||
injectAsync,
|
||||
ComponentFixture,
|
||||
TestComponentBuilder,
|
||||
beforeEachProviders,
|
||||
TestComponentBuilder
|
||||
} from 'angular2/testing';
|
||||
import {
|
||||
it,
|
||||
@@ -13,22 +10,21 @@ import {
|
||||
expect,
|
||||
beforeEach,
|
||||
} from '../../core/facade/testing';
|
||||
import {provide, Component, DebugElement} from 'angular2/core';
|
||||
import {Component} from 'angular2/core';
|
||||
import {By} from 'angular2/platform/browser';
|
||||
|
||||
import {MdButton, MdAnchor} from './button';
|
||||
import {AsyncTestFn, FunctionWithParamTokens} from 'angular2/testing';
|
||||
|
||||
export function main() {
|
||||
describe('MdButton', () => {
|
||||
let builder: TestComponentBuilder;
|
||||
|
||||
beforeEach(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
|
||||
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
builder = tcb;
|
||||
}));
|
||||
|
||||
// General button tests
|
||||
it('should apply class based on color attribute', (done:() => void) => {
|
||||
it('should apply class based on color attribute', (done: () => void) => {
|
||||
return builder.createAsync(TestApp).then((fixture) => {
|
||||
let testComponent = fixture.debugElement.componentInstance;
|
||||
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
|
||||
@@ -49,7 +45,7 @@ export function main() {
|
||||
|
||||
// Regular button tests
|
||||
describe('button[md-button]', () => {
|
||||
it('should handle a click on the button', (done:() => void) => {
|
||||
it('should handle a click on the button', (done: () => void) => {
|
||||
return builder.createAsync(TestApp).then((fixture) => {
|
||||
let testComponent = fixture.debugElement.componentInstance;
|
||||
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
|
||||
@@ -60,7 +56,7 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not increment if disabled', (done:() => void) => {
|
||||
it('should not increment if disabled', (done: () => void) => {
|
||||
return builder.createAsync(TestApp).then((fixture) => {
|
||||
let testComponent = fixture.debugElement.componentInstance;
|
||||
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
|
||||
@@ -79,7 +75,7 @@ export function main() {
|
||||
|
||||
// Anchor button tests
|
||||
describe('a[md-button]', () => {
|
||||
it('should not redirect if disabled',(done:() => void)=>{
|
||||
it('should not redirect if disabled', (done: () => void) => {
|
||||
return builder.createAsync(TestApp).then((fixture) => {
|
||||
let testComponent = fixture.debugElement.componentInstance;
|
||||
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
|
||||
@@ -93,7 +89,7 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should remove tabindex if disabled', (done:() => void) => {
|
||||
it('should remove tabindex if disabled', (done: () => void) => {
|
||||
return builder.createAsync(TestApp).then((fixture) => {
|
||||
let testComponent = fixture.debugElement.componentInstance;
|
||||
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
|
||||
@@ -106,7 +102,7 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should add aria-disabled attribute if disabled', (done:() => void) => {
|
||||
it('should add aria-disabled attribute if disabled', (done: () => void) => {
|
||||
return builder.createAsync(TestApp).then((fixture) => {
|
||||
let testComponent = fixture.debugElement.componentInstance;
|
||||
let buttonDebugElement = fixture.debugElement.query(By.css('a'));
|
||||
@@ -124,16 +120,12 @@ export function main() {
|
||||
});
|
||||
}
|
||||
|
||||
/** Shortcut function to use instead of `injectAsync` for less boilerplate on each `it`. */
|
||||
function testAsync(fn: Function): FunctionWithParamTokens {
|
||||
return injectAsync([], fn);
|
||||
}
|
||||
|
||||
/** Test component that contains an MdButton. */
|
||||
@Component({
|
||||
selector: 'test-app',
|
||||
template: `
|
||||
<button md-button type="button" (click)="increment()" [disabled]="isDisabled" [color]="buttonColor">
|
||||
<button md-button type="button" (click)="increment()"
|
||||
[disabled]="isDisabled" [color]="buttonColor">
|
||||
Go
|
||||
</button>
|
||||
<a href="http://www.google.com" md-button [disabled]="isDisabled" [color]="buttonColor">Link</a>
|
||||
@@ -148,5 +140,3 @@ class TestApp {
|
||||
this.clickCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ export class MdButton {
|
||||
/** Whether a mousedown has occurred on this element in the last 100ms. */
|
||||
isMouseDown: boolean = false;
|
||||
|
||||
setClassList() {return `md-${this.color}`;}
|
||||
setClassList() { return `md-${this.color}`; }
|
||||
|
||||
setMousedown() {
|
||||
// We only *show* the focus style when focus has come to the button via the keyboard.
|
||||
@@ -75,7 +75,7 @@ export class MdAnchor extends MdButton {
|
||||
disabled_: boolean = null;
|
||||
|
||||
@HostBinding('tabIndex')
|
||||
get tabIndex():number {
|
||||
get tabIndex(): number {
|
||||
return this.disabled ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ import {CONST_EXPR} from 'angular2/src/facade/lang';
|
||||
|
||||
<md-card> is a basic content container component that adds the styles of a material design card.
|
||||
|
||||
While you can use this component alone, it also provides a number of preset styles for common card sections, including:
|
||||
While you can use this component alone,
|
||||
it also provides a number of preset styles for common card sections, including:
|
||||
- md-card-title
|
||||
- md-card-subtitle
|
||||
- md-card-content
|
||||
@@ -29,10 +30,11 @@ While you can use this component alone, it also provides a number of preset styl
|
||||
export class MdCard {}
|
||||
|
||||
|
||||
/* The following components don't have any behavior. They simply use content projection to wrap user content
|
||||
for flex layout purposes in <md-card> (and thus allow a cleaner, boilerplate-free API).
|
||||
/* The following components don't have any behavior.
|
||||
They simply use content projection to wrap user content
|
||||
for flex layout purposes in <md-card> (and thus allow a cleaner, boilerplate-free API).
|
||||
|
||||
|
||||
|
||||
<md-card-header> is a component intended to be used within the <md-card> component.
|
||||
It adds styles for a preset header section (i.e. a title, subtitle, and avatar layout).
|
||||
|
||||
@@ -70,4 +72,3 @@ TODO(kara): update link to demo site when it exists
|
||||
export class MdCardTitleGroup {}
|
||||
|
||||
export const MD_CARD_DIRECTIVES: any[] = CONST_EXPR([MdCard, MdCardHeader, MdCardTitleGroup]);
|
||||
|
||||
|
||||
@@ -8,19 +8,19 @@ import {
|
||||
beforeEach,
|
||||
} from '../../core/facade/testing';
|
||||
import {Component, DebugElement} from 'angular2/core';
|
||||
import {By} from 'angular2/platform/browser'
|
||||
import {By} from 'angular2/platform/browser';
|
||||
import {MdProgressCircle} from './progress_circle';
|
||||
|
||||
|
||||
export function main() {
|
||||
describe('MdProgressCircular', () => {
|
||||
let builder:TestComponentBuilder;
|
||||
let builder: TestComponentBuilder;
|
||||
|
||||
beforeEach(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
|
||||
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
builder = tcb;
|
||||
}));
|
||||
|
||||
it('should apply a mode of "determinate" if no mode is provided.', (done:() => void) => {
|
||||
it('should apply a mode of "determinate" if no mode is provided.', (done: () => void) => {
|
||||
builder
|
||||
.overrideTemplate(TestApp, '<md-progress-circle></md-progress-circle>')
|
||||
.createAsync(TestApp)
|
||||
@@ -32,7 +32,7 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should apply a mode of "determinate" if an invalid mode is provided.', (done:() => void) => {
|
||||
it('should apply mode of "determinate" if an invalid mode is provided.', (done: () => void) => {
|
||||
builder
|
||||
.overrideTemplate(TestApp, '<md-progress-circle mode="spinny"></md-progress-circle>')
|
||||
.createAsync(TestApp)
|
||||
@@ -44,7 +44,7 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not modify the mode if a valid mode is provided.', (done:() => void) => {
|
||||
it('should not modify the mode if a valid mode is provided.', (done: () => void) => {
|
||||
builder
|
||||
.overrideTemplate(TestApp, '<md-progress-circle mode="indeterminate"></md-progress-circle>')
|
||||
.createAsync(TestApp)
|
||||
@@ -56,7 +56,7 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should define a default value for the value attribute', (done:() => void) => {
|
||||
it('should define a default value for the value attribute', (done: () => void) => {
|
||||
builder
|
||||
.overrideTemplate(TestApp, '<md-progress-circle></md-progress-circle>')
|
||||
.createAsync(TestApp)
|
||||
@@ -68,7 +68,7 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should clamp the value of the progress between 0 and 100', (done:() => void) => {
|
||||
it('should clamp the value of the progress between 0 and 100', (done: () => void) => {
|
||||
builder
|
||||
.overrideTemplate(TestApp, '<md-progress-circle></md-progress-circle>')
|
||||
.createAsync(TestApp)
|
||||
@@ -104,4 +104,4 @@ function getChildDebugElement(parent: DebugElement, selector: string): DebugElem
|
||||
directives: [MdProgressCircle],
|
||||
template: '',
|
||||
})
|
||||
class TestApp {}
|
||||
class TestApp {}
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import {
|
||||
Attribute,
|
||||
Component,
|
||||
ChangeDetectionStrategy,
|
||||
ElementRef,
|
||||
HostBinding,
|
||||
Input,
|
||||
ViewEncapsulation,
|
||||
Input
|
||||
} from 'angular2/core';
|
||||
import {isPresent, CONST} from 'angular2/src/facade/lang';
|
||||
import {Math} from 'angular2/src/facade/math';
|
||||
|
||||
@@ -24,9 +24,6 @@ import {
|
||||
} from 'angular2/core';
|
||||
|
||||
import {By} from 'angular2/platform/browser';
|
||||
import {Predicate} from 'angular2/src/facade/collection';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/promise';
|
||||
import {TimerWrapper} from 'angular2/src/facade/async';
|
||||
import {MdSidenav, MdSidenavLayout, MD_SIDENAV_DIRECTIVES} from './sidenav';
|
||||
|
||||
|
||||
@@ -38,7 +35,8 @@ function fakeAsyncAdaptor(fn: () => void) {
|
||||
/**
|
||||
* Create a ComponentFixture from the builder. This takes a template and a style for sidenav.
|
||||
*/
|
||||
function createFixture(builder: TestComponentBuilder, template: string, style: string): ComponentFixture {
|
||||
function createFixture(builder: TestComponentBuilder,
|
||||
template: string, style: string): ComponentFixture {
|
||||
let fixture: ComponentFixture = null;
|
||||
// Remove the styles (which remove the animations/transitions).
|
||||
builder
|
||||
@@ -71,10 +69,11 @@ export function main() {
|
||||
let builder: TestComponentBuilder;
|
||||
|
||||
/**
|
||||
* We need to get the template and styles for the sidenav in an Async test. FakeAsync would block indefinitely
|
||||
* on the XHR if we were to create the component async-ly. See https://github.com/angular/angular/issues/5601.
|
||||
* We do some style verification so styles have to match. But we remove the transitions so we only
|
||||
* set the regular `sidenav.css` styling.
|
||||
* We need to get the template and styles for the sidenav in an Async test.
|
||||
* FakeAsync would block indefinitely on the XHR if we were to create the component async-ly.
|
||||
* See https://github.com/angular/angular/issues/5601.
|
||||
* We do some style verification so styles have to match.
|
||||
* But we remove the transitions so we only set the regular `sidenav.css` styling.
|
||||
*/
|
||||
beforeEach(injectAsync([TestComponentBuilder, XHR], (tcb: TestComponentBuilder, xhr: XHR) => {
|
||||
builder = tcb;
|
||||
@@ -111,7 +110,8 @@ export function main() {
|
||||
let sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
|
||||
let sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
|
||||
expect(getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('visible');
|
||||
expect(getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('visible');
|
||||
expect(getComputedStyle(sidenavBackdropElement.nativeElement).visibility)
|
||||
.toEqual('visible');
|
||||
|
||||
// Close it.
|
||||
let closeButtonElement = fixture.debugElement.query(By.css('.close'));
|
||||
@@ -136,13 +136,14 @@ export function main() {
|
||||
expect(getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('hidden');
|
||||
}));
|
||||
|
||||
it('open() and close() return a promise that resolves after the animation ended', fakeAsyncAdaptor(() => {
|
||||
it('open/close() return a promise that resolves after animation end', fakeAsyncAdaptor(() => {
|
||||
let fixture = createFixture(builder, template, style);
|
||||
let sidenav: MdSidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
|
||||
let called: boolean = false;
|
||||
let sidenav: MdSidenav = fixture.debugElement
|
||||
.query(By.directive(MdSidenav)).componentInstance;
|
||||
let called = false;
|
||||
|
||||
sidenav.open().then((_: any) => {
|
||||
called = true
|
||||
called = true;
|
||||
});
|
||||
|
||||
expect(called).toBe(false);
|
||||
@@ -152,7 +153,7 @@ export function main() {
|
||||
|
||||
called = false;
|
||||
sidenav.close().then((_: any) => {
|
||||
called = true
|
||||
called = true;
|
||||
});
|
||||
|
||||
expect(called).toBe(false);
|
||||
@@ -164,7 +165,8 @@ export function main() {
|
||||
|
||||
it('open/close() twice returns the same promise', fakeAsyncAdaptor(() => {
|
||||
let fixture = createFixture(builder, template, style);
|
||||
let sidenav: MdSidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
|
||||
let sidenav: MdSidenav = fixture.debugElement
|
||||
.query(By.directive(MdSidenav)).componentInstance;
|
||||
|
||||
let promise = sidenav.open();
|
||||
expect(sidenav.open()).toBe(promise);
|
||||
@@ -178,12 +180,13 @@ export function main() {
|
||||
|
||||
it('open() then close() cancel animations when called too fast', fakeAsyncAdaptor(() => {
|
||||
let fixture = createFixture(builder, template, style);
|
||||
let sidenav: MdSidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
|
||||
let sidenav: MdSidenav = fixture.debugElement
|
||||
.query(By.directive(MdSidenav)).componentInstance;
|
||||
|
||||
let closePromise: Promise<void>;
|
||||
let openCalled: boolean = false;
|
||||
let openCancelled: boolean = false;
|
||||
let closeCalled: boolean = false;
|
||||
let openCalled = false;
|
||||
let openCancelled = false;
|
||||
let closeCalled = false;
|
||||
|
||||
sidenav.open().then((_: any) => { openCalled = true; }, () => { openCancelled = true; });
|
||||
|
||||
@@ -201,12 +204,12 @@ export function main() {
|
||||
|
||||
it('close() then open() cancel animations when called too fast', fakeAsyncAdaptor(() => {
|
||||
let fixture = createFixture(builder, template, style);
|
||||
let sidenav: MdSidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
|
||||
let sidenav: MdSidenav = fixture.debugElement
|
||||
.query(By.directive(MdSidenav)).componentInstance;
|
||||
|
||||
let openPromise: Promise<void>;
|
||||
let closeCalled: boolean = false;
|
||||
let closeCancelled: boolean = false;
|
||||
let openCalled: boolean = false;
|
||||
let closeCalled = false;
|
||||
let closeCancelled = false;
|
||||
let openCalled = false;
|
||||
|
||||
// First, open the sidenav completely.
|
||||
sidenav.open();
|
||||
|
||||
@@ -9,8 +9,8 @@ declare var Symbol: any;
|
||||
* @param values The list of allowed values. The first value listed will be used as a default if
|
||||
* the set value isn't part of the list of accepted values.
|
||||
*/
|
||||
function OneOfFactory(values: any[]) {
|
||||
return function OneOfMetadata(target: any, key: string): void {
|
||||
function oneOfFactory(values: any[]) {
|
||||
return function oneOfMetadata(target: any, key: string): void {
|
||||
const defaultValue = values[0];
|
||||
|
||||
// Use a fallback if Symbol isn't available.
|
||||
@@ -27,8 +27,7 @@ function OneOfFactory(values: any[]) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export const OneOf = OneOfFactory;
|
||||
export { oneOfFactory as OneOf };
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import {Injector, Provider, PLATFORM_INITIALIZER} from 'angular2/core';
|
||||
import {BaseException, ExceptionHandler} from 'angular2/src/facade/exceptions';
|
||||
import {BaseException} from 'angular2/src/facade/exceptions';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {FunctionWrapper, isPresent, Type} from 'angular2/src/facade/lang';
|
||||
|
||||
export class TestInjector {
|
||||
private _instantiated: boolean = false;
|
||||
|
||||
private _injector: Injector = null;
|
||||
private instantiated_: boolean = false;
|
||||
|
||||
private _providers: Array<Type | Provider | any[]> = [];
|
||||
private injector_: Injector = null;
|
||||
|
||||
private providers_: Array<Type | Provider | any[]> = [];
|
||||
|
||||
reset() {
|
||||
this._injector = null;
|
||||
this._providers = [];
|
||||
this._instantiated = false;
|
||||
this.injector_ = null;
|
||||
this.providers_ = [];
|
||||
this.instantiated_ = false;
|
||||
}
|
||||
|
||||
platformProviders: Array<Type | Provider | any[]> = [];
|
||||
@@ -21,35 +22,35 @@ export class TestInjector {
|
||||
applicationProviders: Array<Type | Provider | any[]> = [];
|
||||
|
||||
addProviders(providers: Array<Type | Provider | any[]>) {
|
||||
if (this._instantiated) {
|
||||
if (this.instantiated_) {
|
||||
throw new BaseException('Cannot add providers after test injector is instantiated');
|
||||
}
|
||||
this._providers = ListWrapper.concat(this._providers, providers);
|
||||
this.providers_ = ListWrapper.concat(this.providers_, providers);
|
||||
}
|
||||
|
||||
createInjector() {
|
||||
var rootInjector = Injector.resolveAndCreate(this.platformProviders);
|
||||
this._injector = rootInjector.resolveAndCreateChild(
|
||||
ListWrapper.concat(this.applicationProviders, this._providers));
|
||||
this._instantiated = true;
|
||||
return this._injector;
|
||||
let rootInjector = Injector.resolveAndCreate(this.platformProviders);
|
||||
this.injector_ = rootInjector.resolveAndCreateChild(
|
||||
ListWrapper.concat(this.applicationProviders, this.providers_));
|
||||
this.instantiated_ = true;
|
||||
return this.injector_;
|
||||
}
|
||||
|
||||
execute(fn: FunctionWithParamTokens): any {
|
||||
if (!this._instantiated) {
|
||||
if (!this.instantiated_) {
|
||||
this.createInjector();
|
||||
}
|
||||
return fn.execute(this._injector);
|
||||
return fn.execute(this.injector_);
|
||||
}
|
||||
}
|
||||
|
||||
var _testInjector: TestInjector = null;
|
||||
let testInjectorCache: TestInjector = null;
|
||||
|
||||
export function getTestInjector() {
|
||||
if (_testInjector == null) {
|
||||
_testInjector = new TestInjector();
|
||||
if (testInjectorCache == null) {
|
||||
testInjectorCache = new TestInjector();
|
||||
}
|
||||
return _testInjector;
|
||||
return testInjectorCache;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,13 +66,13 @@ export function getTestInjector() {
|
||||
*/
|
||||
export function setBaseTestProviders(platformProviders: Array<Type | Provider | any[]>,
|
||||
applicationProviders: Array<Type | Provider | any[]>) {
|
||||
var testInjector = getTestInjector();
|
||||
let testInjector = getTestInjector();
|
||||
if (testInjector.platformProviders.length > 0 || testInjector.applicationProviders.length > 0) {
|
||||
throw new BaseException('Cannot set base providers because it has already been called');
|
||||
}
|
||||
testInjector.platformProviders = platformProviders;
|
||||
testInjector.applicationProviders = applicationProviders;
|
||||
var injector = testInjector.createInjector();
|
||||
let injector = testInjector.createInjector();
|
||||
let inits: Function[] = <Function[]>injector.getOptional(PLATFORM_INITIALIZER);
|
||||
if (isPresent(inits)) {
|
||||
inits.forEach(init => init());
|
||||
@@ -83,7 +84,7 @@ export function setBaseTestProviders(platformProviders: Array<Type | Provider |
|
||||
* Reset the providers for the test injector.
|
||||
*/
|
||||
export function resetBaseTestProviders() {
|
||||
var testInjector = getTestInjector();
|
||||
let testInjector = getTestInjector();
|
||||
testInjector.platformProviders = [];
|
||||
testInjector.applicationProviders = [];
|
||||
testInjector.reset();
|
||||
@@ -142,15 +143,15 @@ export function injectAsync(tokens: any[], fn: Function): FunctionWithParamToken
|
||||
}
|
||||
|
||||
export class FunctionWithParamTokens {
|
||||
constructor(private _tokens: any[], private _fn: Function, public isAsync: boolean) {}
|
||||
constructor(private tokens_: any[], private fn_: Function, public isAsync: boolean) {}
|
||||
|
||||
/**
|
||||
* Returns the value of the executed function.
|
||||
*/
|
||||
execute(injector: Injector): any {
|
||||
var params = this._tokens.map(t => injector.get(t));
|
||||
return FunctionWrapper.apply(this._fn, params);
|
||||
let params = this.tokens_.map(t => injector.get(t));
|
||||
return FunctionWrapper.apply(this.fn_, params);
|
||||
}
|
||||
|
||||
hasToken(token: any): boolean { return this._tokens.indexOf(token) > -1; }
|
||||
hasToken(token: any): boolean { return this.tokens_.indexOf(token) > -1; }
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ import {MdButton, MdAnchor} from '../../components/button/button';
|
||||
export class ButtonDemo {
|
||||
isDisabled: boolean = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@ import {MD_CARD_DIRECTIVES} from '../../components/card/card';
|
||||
styleUrls: ['demo-app/card/card-demo.css'],
|
||||
directives: [MD_CARD_DIRECTIVES, MdButton]
|
||||
})
|
||||
export class CardDemo {}
|
||||
export class CardDemo {}
|
||||
|
||||
@@ -15,4 +15,4 @@ export class ProgressCircleDemo {
|
||||
this.progressValue += val;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@ import {MD_SIDENAV_DIRECTIVES} from '../../components/sidenav/sidenav';
|
||||
styleUrls: ['demo-app/sidenav/sidenav-demo.css'],
|
||||
directives: [MD_SIDENAV_DIRECTIVES, MdButton]
|
||||
})
|
||||
export class SidenavDemo { }
|
||||
export class SidenavDemo { }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {EventEmitter} from 'angular2/src/facade/async';
|
||||
import {Directive, HostBinding, Output, Input} from 'angular2/core';
|
||||
import {OneOf} from "../../core/annotations/one-of";
|
||||
import {OneOf} from '../../core/annotations/one-of';
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import {bootstrap} from 'angular2/platform/browser';
|
||||
import {DemoApp} from './demo-app/demo-app';
|
||||
import {ROUTER_PROVIDERS} from 'angular2/router';
|
||||
import {HashLocationStrategy} from 'angular2/router';
|
||||
import {LocationStrategy} from 'angular2/router';
|
||||
import {provide} from 'angular2/core';
|
||||
|
||||
bootstrap(DemoApp, [
|
||||
ROUTER_PROVIDERS
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Error.stackTraceLimit = Infinity;
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 4000;
|
||||
|
||||
__karma__.loaded = function() {};
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
"no-bitwise": true,
|
||||
"no-shadowed-variable": true,
|
||||
"no-unused-expression": true,
|
||||
"no-unused-variable": true,
|
||||
"no-unused-variable": [true, {"ignore-pattern": "ddescribe|iit|.*_$"}],
|
||||
"one-line": [
|
||||
true,
|
||||
"check-catch",
|
||||
|
||||
Reference in New Issue
Block a user