Skip to content

Commit

Permalink
fix(tests): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Oct 8, 2015
1 parent 5458036 commit 8b725c7
Show file tree
Hide file tree
Showing 26 changed files with 82 additions and 86 deletions.
2 changes: 1 addition & 1 deletion docs/typescript-definition-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
{
id: 'angular2/router',
references: ['./angular2.d.ts'],
remapTypes: {Type: 'ng.Type', InjectableReference: 'ng.InjectableReference'},
remapTypes: {Type: 'ng.Type', InjectableReference: 'ng.InjectableReference', ElementRef: 'ng.ElementRef', DynamicComponentLoader: 'ng.DynamicComponentLoader'},
modules: {'angular2/router': {namespace: 'ngRouter', id: 'angular2/router'}}
},
{
Expand Down
2 changes: 1 addition & 1 deletion karma-dart.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var packageSources = {
'utf': 'packages/utf',

// Local dependencies, transpiled from the source.
'angular2/test/': 'dist/dart/angular2/test/',
'angular2': 'dist/dart/angular2/lib',
'angular2/test/': 'dist/dart/angular2/test/',
'http': 'dist/dart/http/lib',
'angular2_material': 'dist/dart/angular2_material/lib',
'benchpress': 'dist/dart/benchpress/lib',
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/src/core/application_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from 'angular2/src/core/linker/dynamic_component_loader';
import {TestabilityRegistry, Testability} from 'angular2/src/core/testability/testability';
import {Renderer} from 'angular2/src/core/render/api';
import {DomRenderer, DOCUMENT} from 'angular2/src/core/render/render';
import {DomRenderer, DomRenderer_, DOCUMENT} from 'angular2/src/core/render/render';
import {
SharedStylesHost,
DomSharedStylesHost
Expand All @@ -55,7 +55,7 @@ export function applicationDomBindings(): Array<Type | Binding | any[]> {
new Binding(EVENT_MANAGER_PLUGINS, {toClass: DomEventsPlugin, multi: true}),
new Binding(EVENT_MANAGER_PLUGINS, {toClass: KeyEventsPlugin, multi: true}),
new Binding(EVENT_MANAGER_PLUGINS, {toClass: HammerGesturesPlugin, multi: true}),
DomRenderer,
bind(DomRenderer).toClass(DomRenderer_),
bind(Renderer).toAlias(DomRenderer),
DomSharedStylesHost,
bind(SharedStylesHost).toAlias(DomSharedStylesHost),
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/application_ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function _componentBindings(appComponentType: Type): Array<Type | Binding | any[
return componentRef;
});
},
[bind(DynamicComponentLoader).toClass(DynamicComponentLoader_), Injector]),
[DynamicComponentLoader, Injector]),

bind(appComponentType)
.toFactory((p: Promise<any>) => p.then(ref => ref.instance), [APP_COMPONENT_REF_PROMISE]),
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/compiler/runtime_compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async';
export abstract class RuntimeCompiler extends Compiler {}

@Injectable()
export class RuntimeCompiler_ extends Compiler_ {
export class RuntimeCompiler_ extends Compiler_ implements RuntimeCompiler {
constructor(_protoViewFactory: ProtoViewFactory, private _templateCompiler: TemplateCompiler) {
super(_protoViewFactory);
}
Expand Down
3 changes: 3 additions & 0 deletions modules/angular2/src/core/di/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export class CyclicDependencyError extends AbstractBindingError {
* ```
*/
export abstract class InstantiationError extends WrappedException {
constructor(message, originalException, originalStack, context) {
super(message, originalException, originalStack, context);
}
abstract addKey(injector: Injector, key: Key): void;
get wrapperMessage(): string { return unimplemented(); };
get causeKey(): Key { return unimplemented(); };
Expand Down
3 changes: 1 addition & 2 deletions modules/angular2/src/core/linker/element_injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
BindingWithVisibility,
DependencyProvider
} from 'angular2/src/core/di/injector';
import {resolveBinding, ResolvedFactory} from 'angular2/src/core/di/binding';
import {resolveBinding, ResolvedFactory, ResolvedBinding_} from 'angular2/src/core/di/binding';

import {AttributeMetadata, QueryMetadata} from '../metadata/di';

Expand All @@ -53,7 +53,6 @@ import {PipeBinding} from '../pipes/pipe_binding';

import {LifecycleHooks} from './interfaces';
import {ViewContainerRef_} from "./view_container_ref";
import {ResolvedBinding_} from "../di/binding";

var _staticKeys;

Expand Down
1 change: 0 additions & 1 deletion modules/angular2/src/core/linker/element_ref.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {BaseException, unimplemented} from 'angular2/src/core/facade/exceptions';
import {ViewRef, ViewRef_} from './view_ref';
import {RenderViewRef, RenderElementRef, Renderer} from 'angular2/src/core/render/api';
import {ChangeDetectorRef} from "../change_detection/change_detector_ref";

/**
* Represents a location in a View that has an injection, change-detection and render context
Expand Down
3 changes: 1 addition & 2 deletions modules/angular2/src/core/pipes/pipe_binding.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {Type} from 'angular2/src/core/facade/lang';
import {ResolvedFactory, resolveBinding} from 'angular2/src/core/di/binding';
import {ResolvedFactory, resolveBinding, ResolvedBinding_} from 'angular2/src/core/di/binding';
import {Key, ResolvedBinding, Binding} from 'angular2/src/core/di';
import {PipeMetadata} from '../metadata/directives';
import {ResolvedBinding_} from "../di/binding";

export class PipeBinding extends ResolvedBinding_ {
constructor(public name: string, public pure: boolean, key: Key,
Expand Down
10 changes: 8 additions & 2 deletions modules/angular2/src/core/reflection/reflection_capabilities.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import {Type, isPresent, isFunction, global, stringify} from 'angular2/src/core/facade/lang';
import {
Type,
isPresent,
isFunction,
global,
stringify,
ConcreteType
} from 'angular2/src/core/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
import {ListWrapper} from 'angular2/src/core/facade/collection';
import {GetterFn, SetterFn, MethodFn} from './types';
import {PlatformReflectionCapabilities} from 'platform_reflection_capabilities';
import {ConcreteType} from "../facade/lang";

export class ReflectionCapabilities implements PlatformReflectionCapabilities {
private _reflect: any;
Expand Down
3 changes: 1 addition & 2 deletions modules/angular2/src/core/util/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {global, Type, isFunction, stringify} from 'angular2/src/core/facade/lang';
import {ConcreteType} from "../facade/lang";
import {ConcreteType, global, Type, isFunction, stringify} from 'angular2/src/core/facade/lang';

/**
* Declares the interface to be used with {@link Class}.
Expand Down
4 changes: 4 additions & 0 deletions modules/angular2/src/core/zone/ng_zone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,7 @@ class NgZone {
zoneValues: {'_innerZone': true});
}
}

class NgZone_ extends NgZone {
NgZone_({bool enableLongStackTrace}) : super(enableLongStackTrace: enableLongStackTrace);
}
83 changes: 34 additions & 49 deletions modules/angular2/src/router/router_outlet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async';
import {StringMapWrapper} from 'angular2/src/core/facade/collection';
import {isBlank, isPresent} from 'angular2/src/core/facade/lang';
import {isBlank, isPresent, Type} from 'angular2/src/core/facade/lang';
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';

import {Directive, Attribute} from 'angular2/src/core/metadata';
Expand All @@ -12,7 +12,6 @@ import {ComponentInstruction, RouteParams} from './instruction';
import {ROUTE_DATA} from './route_data';
import * as hookMod from './lifecycle_annotations';
import {hasLifecycleHook} from './route_lifecycle_reflector';
import {Type} from "../core/facade/lang";

let _resolveToTrue = PromiseWrapper.resolve(true);

Expand All @@ -25,59 +24,14 @@ let _resolveToTrue = PromiseWrapper.resolve(true);
* <router-outlet></router-outlet>
* ```
*/
export abstract class RouterOutlet {
name: string = null;

/**
* Called by the Router to instantiate a new component during the commit phase of a navigation.
* This method in turn is responsible for calling the `onActivate` hook of its child.
*/
abstract activate(nextInstruction: ComponentInstruction): Promise<any>;

/**
* Called by the {@link Router} during the commit phase of a navigation when an outlet
* reuses a component between different routes.
* This method in turn is responsible for calling the `onReuse` hook of its child.
*/
abstract reuse(nextInstruction: ComponentInstruction): Promise<any>;

/**
* Called by the {@link Router} when an outlet reuses a component across navigations.
* This method in turn is responsible for calling the `onReuse` hook of its child.
*/
abstract deactivate(nextInstruction: ComponentInstruction): Promise<any>;

/**
* Called by the {@link Router} during recognition phase of a navigation.
*
* If this resolves to `false`, the given navigation is cancelled.
*
* This method delegates to the child component's `canDeactivate` hook if it exists,
* and otherwise resolves to true.
*/
abstract canDeactivate(nextInstruction: ComponentInstruction): Promise<boolean>;

/**
* Called by the {@link Router} during recognition phase of a navigation.
*
* If the new child component has a different Type than the existing child component,
* this will resolve to `false`. You can't reuse an old component when the new component
* is of a different Type.
*
* Otherwise, this method delegates to the child component's `canReuse` hook if it exists,
* or resolves to true if the hook is not present.
*/
abstract canReuse(nextInstruction: ComponentInstruction): Promise<boolean>;
}

@Directive({selector: 'router-outlet'})
export class RouterOutlet_ extends RouterOutlet {
export class RouterOutlet {
name: string = null;
private _componentRef: ComponentRef = null;
private _currentInstruction: ComponentInstruction = null;

constructor(private _elementRef: ElementRef, private _loader: DynamicComponentLoader,
private _parentRouter: routerMod.Router, @Attribute('name') nameAttr: string) {
super();
if (isPresent(nameAttr)) {
this.name = nameAttr;
this._parentRouter.registerAuxOutlet(this);
Expand All @@ -86,6 +40,10 @@ export class RouterOutlet_ extends RouterOutlet {
}
}

/**
* Called by the Router to instantiate a new component during the commit phase of a navigation.
* This method in turn is responsible for calling the `onActivate` hook of its child.
*/
activate(nextInstruction: ComponentInstruction): Promise<any> {
var previousInstruction = this._currentInstruction;
this._currentInstruction = nextInstruction;
Expand All @@ -107,6 +65,11 @@ export class RouterOutlet_ extends RouterOutlet {
});
}

/**
* Called by the {@link Router} during the commit phase of a navigation when an outlet
* reuses a component between different routes.
* This method in turn is responsible for calling the `onReuse` hook of its child.
*/
reuse(nextInstruction: ComponentInstruction): Promise<any> {
var previousInstruction = this._currentInstruction;
this._currentInstruction = nextInstruction;
Expand All @@ -120,6 +83,10 @@ export class RouterOutlet_ extends RouterOutlet {
true);
}

/**
* Called by the {@link Router} when an outlet reuses a component across navigations.
* This method in turn is responsible for calling the `onReuse` hook of its child.
*/
deactivate(nextInstruction: ComponentInstruction): Promise<any> {
var next = _resolveToTrue;
if (isPresent(this._componentRef) && isPresent(this._currentInstruction) &&
Expand All @@ -135,6 +102,14 @@ export class RouterOutlet_ extends RouterOutlet {
});
}

/**
* Called by the {@link Router} during recognition phase of a navigation.
*
* If this resolves to `false`, the given navigation is cancelled.
*
* This method delegates to the child component's `canDeactivate` hook if it exists,
* and otherwise resolves to true.
*/
canDeactivate(nextInstruction: ComponentInstruction): Promise<boolean> {
if (isBlank(this._currentInstruction)) {
return _resolveToTrue;
Expand All @@ -146,6 +121,16 @@ export class RouterOutlet_ extends RouterOutlet {
return _resolveToTrue;
}

/**
* Called by the {@link Router} during recognition phase of a navigation.
*
* If the new child component has a different Type than the existing child component,
* this will resolve to `false`. You can't reuse an old component when the new component
* is of a different Type.
*
* Otherwise, this method delegates to the child component's `canReuse` hook if it exists,
* or resolves to true if the hook is not present.
*/
canReuse(nextInstruction: ComponentInstruction): Promise<boolean> {
var result;

Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/test/core/application_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {bind, Inject, Injector, LifeCycle} from 'angular2/core';
import {ExceptionHandler} from 'angular2/src/core/facade/exceptions';
import {Testability, TestabilityRegistry} from 'angular2/src/core/testability/testability';
import {IS_DART} from '../platform';
import {ComponentRef_} from "../../src/core/linker/dynamic_component_loader";
import {ComponentRef_} from "angular2/src/core/linker/dynamic_component_loader";

@Component({selector: 'hello-app'})
@View({template: '{{greeting}} world!'})
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/test/core/life_cycle/life_cycle_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
inject
} from 'angular2/test_lib';
import {SpyChangeDetector} from '../spies';
import {LifeCycle_} from "../../../src/core/life_cycle/life_cycle";
import {LifeCycle_} from "angular2/src/core/life_cycle/life_cycle";

export function main() {
describe("LifeCycle", () => {
Expand Down
8 changes: 5 additions & 3 deletions modules/angular2/test/core/linker/compiler_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {Compiler} from 'angular2/src/core/linker/compiler';
import {ProtoViewFactory} from 'angular2/src/core/linker/proto_view_factory';
import {reflector, ReflectionInfo} from 'angular2/src/core/reflection/reflection';
import {AppProtoView} from 'angular2/src/core/linker/view';
import {Compiler_} from "../../../src/core/linker/compiler";
import {Compiler_} from "angular2/src/core/linker/compiler";

export function main() {
describe('Compiler', () => {
Expand All @@ -37,8 +37,10 @@ export function main() {
protoViewFactorySpy = new SpyProtoViewFactory();
someProtoView = new AppProtoView(null, null, null, null, null, null);
protoViewFactorySpy.spy('createHost').andReturn(someProtoView);
return
[bind(ProtoViewFactory).toValue(protoViewFactorySpy), bind(Compiler).toClass(Compiler_)];
var factoryBinding = bind(ProtoViewFactory).toValue(protoViewFactorySpy);
var classBinding = bind(Compiler).toClass(Compiler_);
var bindings = [factoryBinding, classBinding];
return bindings;
});

beforeEach(inject([Compiler], (_compiler) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {DynamicComponentLoader} from 'angular2/src/core/linker/dynamic_component
import {ElementRef} from 'angular2/src/core/linker/element_ref';
import {DOCUMENT} from 'angular2/src/core/render/render';
import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {RootTestComponent_} from "../../../src/test_lib/test_component_builder";
import {RootTestComponent_} from "angular2/src/test_lib/test_component_builder";

export function main() {
describe('DynamicComponentLoader', function() {
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/test/core/linker/element_injector_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
} from 'angular2/src/core/metadata';
import {OnDestroy} from 'angular2/lifecycle_hooks';
import {bind, Injector, Binding, Optional, Inject, Injectable, Self, SkipSelf, InjectMetadata, Host, HostMetadata, SkipSelfMetadata} from 'angular2/core';
import {ViewContainerRef} from 'angular2/src/core/linker/view_container_ref';
import {ViewContainerRef, ViewContainerRef_} from 'angular2/src/core/linker/view_container_ref';
import {TemplateRef, TemplateRef_} from 'angular2/src/core/linker/template_ref';
import {ElementRef} from 'angular2/src/core/linker/element_ref';
import {DynamicChangeDetector, ChangeDetectorRef, Parser, Lexer} from 'angular2/src/core/change_detection/change_detection';
Expand Down Expand Up @@ -905,7 +905,7 @@ export function main() {

it('should inject ViewContainerRef', () => {
var inj = injector(ListWrapper.concat([NeedsViewContainer], extraBindings));
expect(inj.get(NeedsViewContainer).viewContainer).toBeAnInstanceOf(ViewContainerRef);
expect(inj.get(NeedsViewContainer).viewContainer).toBeAnInstanceOf(ViewContainerRef_);
});

it("should inject TemplateRef", () => {
Expand Down
5 changes: 2 additions & 3 deletions modules/angular2/test/core/linker/integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import {TemplateRef} from 'angular2/src/core/linker/template_ref';

import {DomRenderer} from 'angular2/src/core/render/dom/dom_renderer';
import {IS_DART} from '../../platform';
import {Compiler_} from "../../../src/core/linker/compiler";
import {Compiler_} from "angular2/src/core/linker/compiler";

const ANCHOR_ELEMENT = CONST_EXPR(new OpaqueToken('AnchorElement'));

Expand Down Expand Up @@ -1018,9 +1018,8 @@ export function main() {
}));

describe('dynamic ViewContainers', () => {

it('should allow to create a ViewContainerRef at any bound location',
inject([TestComponentBuilder, AsyncTestCompleter, bind(Compiler).toClass(Compiler_)],
inject([TestComponentBuilder, AsyncTestCompleter, Compiler],
(tcb: TestComponentBuilder, async, compiler) => {
tcb.overrideView(MyComp, new ViewMetadata({
template: '<div><dynamic-vp #dynamic></dynamic-vp></div>',
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/test/core/pipes/spies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ChangeDetectorRef} from 'angular2/src/core/change_detection/change_detection';
import {ChangeDetectorRef_} from 'angular2/src/core/change_detection/change_detector_ref';

import {SpyObject, proxy} from 'angular2/test_lib';

export class SpyChangeDetectorRef extends SpyObject {
constructor() { super(ChangeDetectorRef); }
constructor() { super(ChangeDetectorRef_); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class FakeEventManagerPlugin extends EventManagerPlugin {

class FakeNgZone extends NgZone_ {
constructor() { super({enableLongStackTrace: false}); }

run(fn) { fn(); }

runOutsideAngular(fn) { return fn(); }
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/test/core/spies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SpyView extends SpyObject implements AppView {
}

@proxy
class SpyElementRef extends SpyObject implements ElementRef {
class SpyElementRef extends SpyObject implements ElementRef_ {
noSuchMethod(m) => super.noSuchMethod(m);
}

Expand Down
Loading

0 comments on commit 8b725c7

Please sign in to comment.