refactor(ts'ify): ts’ify mocks, directives and test_lib
Also cleans up global types.
This commit is contained in:
15
modules/angular2/src/mock/ng_zone_mock.js
vendored
15
modules/angular2/src/mock/ng_zone_mock.js
vendored
@ -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();
|
||||
}
|
||||
}
|
9
modules/angular2/src/mock/ng_zone_mock.ts
Normal file
9
modules/angular2/src/mock/ng_zone_mock.ts
Normal 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(); }
|
||||
}
|
@ -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`);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 {
|
Reference in New Issue
Block a user