refactor(ts'ify): ts’ify mocks, directives and test_lib

Also cleans up global types.
This commit is contained in:
Tobias Bosch
2015-05-20 17:19:46 -07:00
parent c5996529c3
commit aec51d616b
51 changed files with 610 additions and 671 deletions

View File

@ -1,15 +0,0 @@
import {NgZone} from 'angular2/src/core/zone/ng_zone';
export class MockNgZone extends NgZone {
constructor() {
super({enableLongStackTrace: false});
}
run(fn) {
return fn();
}
runOutsideAngular(fn) {
return fn();
}
}

View File

@ -0,0 +1,9 @@
import {NgZone} from 'angular2/src/core/zone/ng_zone';
export class MockNgZone extends NgZone {
constructor() { super({enableLongStackTrace: false}); }
run(fn) { return fn(); }
runOutsideAngular(fn) { return fn(); }
}

View File

@ -8,7 +8,7 @@ export class MockTemplateResolver extends TemplateResolver {
_templates: Map<Type, View>;
_inlineTemplates: Map<Type, string>;
_templateCache: Map<Type, View>;
_directiveOverrides: Map<Type, Type>;
_directiveOverrides: Map<Type, Map<Type, Type>>;
constructor() {
super();
@ -62,7 +62,8 @@ export class MockTemplateResolver extends TemplateResolver {
/**
* Returns the {@link View} for a component:
* - Set the {@link View} to the overridden template when it exists or fallback to the default `TemplateResolver`,
* - Set the {@link View} to the overridden template when it exists or fallback to the default
* `TemplateResolver`,
* see `setView`.
* - Override the directives, see `overrideTemplateDirective`.
* - Override the @View definition, see `setInlineTemplate`.
@ -91,24 +92,18 @@ export class MockTemplateResolver extends TemplateResolver {
MapWrapper.forEach(overrides, (to, from) => {
var srcIndex = directives.indexOf(from);
if (srcIndex == -1) {
throw new BaseException(`Overriden directive ${stringify(from)} not found in the template of ${stringify(component)}`);
throw new BaseException(
`Overriden directive ${stringify(from)} not found in the template of ${stringify(component)}`);
}
directives[srcIndex] = to;
});
view = new View({
template: view.template,
templateUrl: view.templateUrl,
directives: directives
});
view = new View(
{template: view.template, templateUrl: view.templateUrl, directives: directives});
}
var inlineTemplate = MapWrapper.get(this._inlineTemplates, component);
if (isPresent(inlineTemplate)) {
view = new View({
template: inlineTemplate,
templateUrl: null,
directives: view.directives
});
view = new View({template: inlineTemplate, templateUrl: null, directives: view.directives});
}
MapWrapper.set(this._templateCache, component, view);
@ -127,7 +122,8 @@ export class MockTemplateResolver extends TemplateResolver {
var cached = MapWrapper.get(this._templateCache, component);
if (isPresent(cached)) {
throw new BaseException(`The component ${stringify(component)} has already been compiled, its configuration can not be changed`);
throw new BaseException(
`The component ${stringify(component)} has already been compiled, its configuration can not be changed`);
}
}
}

View File

@ -4,9 +4,9 @@ import {isBlank, isPresent, normalizeBlank, BaseException} from 'angular2/src/fa
import {PromiseWrapper, Promise} from 'angular2/src/facade/async';
export class MockXHR extends XHR {
_expectations: List<_Expectation>;
_definitions: Map;
_requests: List<Promise>;
private _expectations: List<_Expectation>;
private _definitions: Map<string, string>;
private _requests: List<Promise<string>>;
constructor() {
super();
@ -26,9 +26,7 @@ export class MockXHR extends XHR {
ListWrapper.push(this._expectations, expectation);
}
when(url: string, response: string) {
MapWrapper.set(this._definitions, url, response);
}
when(url: string, response: string) { MapWrapper.set(this._definitions, url, response); }
flush() {
if (this._requests.length === 0) {
@ -55,7 +53,7 @@ export class MockXHR extends XHR {
throw new BaseException(`Unsatisfied requests: ${ListWrapper.join(urls, ', ')}`);
}
_processRequest(request: _PendingRequest) {
private _processRequest(request: _PendingRequest) {
var url = request.url;
if (this._expectations.length > 0) {
@ -94,9 +92,7 @@ class _PendingRequest {
}
}
getPromise(): Promise<string> {
return this.completer.promise;
}
getPromise(): Promise<string> { return this.completer.promise; }
}
class _Expectation {