refactor(tests): removed @IMPLEMENTS

This commit is contained in:
vsavkin 2015-08-26 11:41:41 -07:00
parent 457eb5d69c
commit 343dcfa0c0
43 changed files with 402 additions and 426 deletions

View File

@ -4,12 +4,6 @@ function CONST() {
}); });
} }
function IMPLEMENTS(_) {
return (function(t) {
return t;
});
}
function CONST_EXPR(expr) { function CONST_EXPR(expr) {
return expr; return expr;
} }

View File

@ -23,11 +23,6 @@ class ABSTRACT {
const ABSTRACT(); const ABSTRACT();
} }
class IMPLEMENTS {
final interfaceClass;
const IMPLEMENTS(this.interfaceClass);
}
bool isPresent(obj) => obj != null; bool isPresent(obj) => obj != null;
bool isBlank(obj) => obj == null; bool isBlank(obj) => obj == null;
bool isString(obj) => obj is String; bool isString(obj) => obj is String;

View File

@ -71,13 +71,6 @@ export function ABSTRACT(): ClassDecorator {
return (t) => t; return (t) => t;
} }
// Note: This is only a marker annotation needed for ts2dart.
// This is written so that is can be used as a Traceur annotation
// or a Typescript decorator.
export function IMPLEMENTS(_): ClassDecorator {
return (t) => t;
}
export function isPresent(obj: any): boolean { export function isPresent(obj: any): boolean {
return obj !== undefined && obj !== null; return obj !== undefined && obj !== null;
} }

View File

@ -5,15 +5,14 @@ import {ReadyStates} from '../enums';
import {Connection, ConnectionBackend} from '../interfaces'; import {Connection, ConnectionBackend} from '../interfaces';
import {ObservableWrapper, EventEmitter} from 'angular2/src/core/facade/async'; import {ObservableWrapper, EventEmitter} from 'angular2/src/core/facade/async';
import {isPresent} from 'angular2/src/core/facade/lang'; import {isPresent} from 'angular2/src/core/facade/lang';
import {IMPLEMENTS, BaseException} from 'angular2/src/core/facade/lang'; import {BaseException} from 'angular2/src/core/facade/lang';
/** /**
* *
* Mock Connection to represent a {@link Connection} for tests. * Mock Connection to represent a {@link Connection} for tests.
* *
**/ **/
@IMPLEMENTS(Connection) export class MockConnection implements Connection {
export class MockConnection {
// TODO Name `readyState` should change to be more generic, and states could be made to be more // TODO Name `readyState` should change to be more generic, and states could be made to be more
// descriptive than XHR states. // descriptive than XHR states.
/** /**
@ -130,8 +129,7 @@ export class MockConnection {
* This method only exists in the mock implementation, not in real Backends. * This method only exists in the mock implementation, not in real Backends.
**/ **/
@Injectable() @Injectable()
@IMPLEMENTS(ConnectionBackend) export class MockBackend implements ConnectionBackend {
export class MockBackend {
/** /**
* {@link EventEmitter} * {@link EventEmitter}
* of {@link MockConnection} instances that have been created by this backend. Can be subscribed * of {@link MockConnection} instances that have been created by this backend. Can be subscribed

View File

@ -1,26 +1,12 @@
import {SpyObject, proxy} from 'angular2/test_lib';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async'; import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async';
import {List, ListWrapper} from 'angular2/src/core/facade/collection'; import {List, ListWrapper} from 'angular2/src/core/facade/collection';
import {Location} from 'angular2/src/router/location'; import {Location} from 'angular2/src/router/location';
export class SpyLocation implements Location {
@proxy urlChanges: List<string> = [];
@IMPLEMENTS(Location) _path: string = '';
export class SpyLocation extends SpyObject { _subject: EventEmitter = new EventEmitter();
urlChanges: List<string>; _baseHref: string = '';
_path: string;
_subject: EventEmitter;
_baseHref: string;
constructor() {
super();
this._path = '';
this.urlChanges = [];
this._subject = new EventEmitter();
this._baseHref = '';
}
setInitialPath(url: string) { this._path = url; } setInitialPath(url: string) { this._path = url; }
@ -54,5 +40,7 @@ export class SpyLocation extends SpyObject {
ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn); ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
} }
noSuchMethod(m: any) { super.noSuchMethod(m); } // TODO: remove these once Location is an interface, and can be implemented cleanly
platformStrategy: any = null;
normalize(url: string): string { return null; }
} }

View File

@ -18,12 +18,12 @@ export const APP_BASE_HREF: OpaqueToken = CONST_EXPR(new OpaqueToken('appBaseHre
*/ */
@Injectable() @Injectable()
export class Location { export class Location {
private _subject: EventEmitter = new EventEmitter(); _subject: EventEmitter = new EventEmitter();
private _baseHref: string; _baseHref: string;
constructor(public _platformStrategy: LocationStrategy, constructor(public platformStrategy: LocationStrategy,
@Optional() @Inject(APP_BASE_HREF) href?: string) { @Optional() @Inject(APP_BASE_HREF) href?: string) {
var browserBaseHref = isPresent(href) ? href : this._platformStrategy.getBaseHref(); var browserBaseHref = isPresent(href) ? href : this.platformStrategy.getBaseHref();
if (isBlank(browserBaseHref)) { if (isBlank(browserBaseHref)) {
throw new BaseException( throw new BaseException(
@ -31,48 +31,31 @@ export class Location {
} }
this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref)); this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref));
this._platformStrategy.onPopState((_) => this._onPopState(_)); this.platformStrategy.onPopState(
(_) => { ObservableWrapper.callNext(this._subject, {'url': this.path(), 'pop': true}); });
} }
_onPopState(_): void { path(): string { return this.normalize(this.platformStrategy.path()); }
ObservableWrapper.callNext(this._subject, {'url': this.path(), 'pop': true});
}
path(): string { return this.normalize(this._platformStrategy.path()); }
normalize(url: string): string { normalize(url: string): string {
return stripTrailingSlash(this._stripBaseHref(stripIndexHtml(url))); return stripTrailingSlash(_stripBaseHref(this._baseHref, stripIndexHtml(url)));
} }
normalizeAbsolutely(url: string): string { normalizeAbsolutely(url: string): string {
if (!url.startsWith('/')) { if (!url.startsWith('/')) {
url = '/' + url; url = '/' + url;
} }
return stripTrailingSlash(this._addBaseHref(url)); return stripTrailingSlash(_addBaseHref(this._baseHref, url));
}
_stripBaseHref(url: string): string {
if (this._baseHref.length > 0 && url.startsWith(this._baseHref)) {
return url.substring(this._baseHref.length);
}
return url;
}
_addBaseHref(url: string): string {
if (!url.startsWith(this._baseHref)) {
return this._baseHref + url;
}
return url;
} }
go(url: string): void { go(url: string): void {
var finalUrl = this.normalizeAbsolutely(url); var finalUrl = this.normalizeAbsolutely(url);
this._platformStrategy.pushState(null, '', finalUrl); this.platformStrategy.pushState(null, '', finalUrl);
} }
forward(): void { this._platformStrategy.forward(); } forward(): void { this.platformStrategy.forward(); }
back(): void { this._platformStrategy.back(); } back(): void { this.platformStrategy.back(); }
subscribe(onNext: (value: any) => void, onThrow: (exception: any) => void = null, subscribe(onNext: (value: any) => void, onThrow: (exception: any) => void = null,
onReturn: () => void = null): void { onReturn: () => void = null): void {
@ -80,7 +63,19 @@ export class Location {
} }
} }
function _stripBaseHref(baseHref: string, url: string): string {
if (baseHref.length > 0 && url.startsWith(baseHref)) {
return url.substring(baseHref.length);
}
return url;
}
function _addBaseHref(baseHref: string, url: string): string {
if (!url.startsWith(baseHref)) {
return baseHref + url;
}
return url;
}
function stripIndexHtml(url: string): string { function stripIndexHtml(url: string): string {
if (/\/index.html$/g.test(url)) { if (/\/index.html$/g.test(url)) {

View File

@ -15,7 +15,6 @@ import {
List, List,
ListWrapper ListWrapper
} from 'angular2/src/core/facade/collection'; } from 'angular2/src/core/facade/collection';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import {RouteHandler} from './route_handler'; import {RouteHandler} from './route_handler';
import {Url, RootUrl, serializeParams} from './url_parser'; import {Url, RootUrl, serializeParams} from './url_parser';

View File

@ -1,36 +0,0 @@
library test_lib.spies;
import 'package:angular2/src/core/change_detection/change_detection.dart';
import 'package:angular2/di.dart';
import './test_lib.dart';
@proxy
class SpyChangeDetector extends SpyObject implements ChangeDetector {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyProtoChangeDetector extends SpyObject implements ProtoChangeDetector {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyDependencyProvider extends SpyObject implements DependencyProvider {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyChangeDetectorRef extends SpyObject implements ChangeDetectorRef {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyIterableDifferFactory extends SpyObject
implements IterableDifferFactory {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyInjector extends SpyObject implements Injector {
noSuchMethod(m) => super.noSuchMethod(m);
}

View File

@ -1,28 +0,0 @@
import {
ChangeDetector,
ChangeDetectorRef,
ProtoChangeDetector,
DynamicChangeDetector
} from 'angular2/src/core/change_detection/change_detection';
import {DependencyProvider} from 'angular2/di';
import {SpyObject, proxy} from './test_lib';
export class SpyChangeDetector extends SpyObject {
constructor() { super(DynamicChangeDetector); }
}
export class SpyProtoChangeDetector extends SpyObject {
constructor() { super(DynamicChangeDetector); }
}
export class SpyDependencyProvider extends SpyObject {}
export class SpyIterableDifferFactory extends SpyObject {}
export class SpyInjector extends SpyObject {}
export class SpyChangeDetectorRef extends SpyObject {
constructor() { super(ChangeDetectorRef); }
}

View File

@ -209,6 +209,10 @@ class SpyObject extends gns.SpyObject {
SpyFunction spy(String funcName) => SpyFunction spy(String funcName) =>
_spyFuncs.putIfAbsent(funcName, () => new SpyFunction(funcName)); _spyFuncs.putIfAbsent(funcName, () => new SpyFunction(funcName));
void prop(String funcName, value) {
_spyFuncs.putIfAbsent("get:${funcName}", () => new SpyFunction(funcName)).andReturn(value);
}
static stub([object = null, config = null, overrides = null]) { static stub([object = null, config = null, overrides = null]) {
if (object is! SpyObject) { if (object is! SpyObject) {
overrides = config; overrides = config;

View File

@ -353,6 +353,8 @@ export class SpyObject {
return this[name]; return this[name];
} }
prop(name, value) { this[name] = value; }
static stub(object = null, config = null, overrides = null) { static stub(object = null, config = null, overrides = null) {
if (!(object instanceof SpyObject)) { if (!(object instanceof SpyObject)) {
overrides = config; overrides = config;

View File

@ -1,14 +1,6 @@
import { import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
ddescribe,
describe, import {SpyProtoChangeDetector} from '../spies';
it,
iit,
xit,
expect,
beforeEach,
afterEach,
SpyProtoChangeDetector
} from 'angular2/test_lib';
import { import {
PreGeneratedChangeDetection, PreGeneratedChangeDetection,

View File

@ -1,14 +1,5 @@
import { import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
ddescribe, import {SpyIterableDifferFactory} from '../../spies';
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach,
SpyIterableDifferFactory
} from 'angular2/test_lib';
import {IterableDiffers} from 'angular2/src/core/change_detection/differs/iterable_differs'; import {IterableDiffers} from 'angular2/src/core/change_detection/differs/iterable_differs';
import {Injector, bind} from 'angular2/di'; import {Injector, bind} from 'angular2/di';

View File

@ -8,11 +8,9 @@ import {
expect, expect,
iit, iit,
inject, inject,
it, it
SpyObject,
proxy
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {SpyRenderCompiler, SpyDirectiveResolver} from '../spies';
import { import {
List, List,
ListWrapper, ListWrapper,
@ -20,14 +18,7 @@ import {
MapWrapper, MapWrapper,
StringMapWrapper StringMapWrapper
} from 'angular2/src/core/facade/collection'; } from 'angular2/src/core/facade/collection';
import { import {Type, isBlank, stringify, isPresent, isArray} from 'angular2/src/core/facade/lang';
IMPLEMENTS,
Type,
isBlank,
stringify,
isPresent,
isArray
} from 'angular2/src/core/facade/lang';
import {PromiseCompleter, PromiseWrapper, Promise} from 'angular2/src/core/facade/async'; import {PromiseCompleter, PromiseWrapper, Promise} from 'angular2/src/core/facade/async';
import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler'; import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
@ -58,7 +49,6 @@ import {
RenderElementBinder RenderElementBinder
} from 'angular2/src/core/render/api'; } from 'angular2/src/core/render/api';
// TODO(tbosch): Spys don't support named modules... // TODO(tbosch): Spys don't support named modules...
import {RenderCompiler} from 'angular2/src/core/render/api';
import {PipeBinding} from 'angular2/src/core/pipes/pipe_binding'; import {PipeBinding} from 'angular2/src/core/pipes/pipe_binding';
@ -718,20 +708,6 @@ class DirectiveWithAttributes {
constructor(@Attribute('someAttr') someAttr: String) {} constructor(@Attribute('someAttr') someAttr: String) {}
} }
@proxy
@IMPLEMENTS(RenderCompiler)
class SpyRenderCompiler extends SpyObject {
constructor() { super(RenderCompiler); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}
@proxy
@IMPLEMENTS(DirectiveResolver)
class SpyDirectiveResolver extends SpyObject {
constructor() { super(DirectiveResolver); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}
class FakeViewResolver extends ViewResolver { class FakeViewResolver extends ViewResolver {
_cmpViews: Map<Type, ViewMetadata> = new Map(); _cmpViews: Map<Type, ViewMetadata> = new Map();

View File

@ -10,14 +10,13 @@ import {
xdescribe, xdescribe,
expect, expect,
beforeEach, beforeEach,
SpyObject,
proxy,
inject, inject,
AsyncTestCompleter, AsyncTestCompleter,
el, el,
containsRegexp containsRegexp
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {isBlank, isPresent, IMPLEMENTS, stringify} from 'angular2/src/core/facade/lang'; import {SpyView, SpyElementRef} from '../spies';
import {isBlank, isPresent, stringify} from 'angular2/src/core/facade/lang';
import { import {
ListWrapper, ListWrapper,
MapWrapper, MapWrapper,
@ -41,32 +40,17 @@ import {
LifecycleEvent LifecycleEvent
} from 'angular2/metadata'; } from 'angular2/metadata';
import {bind, Injector, Binding, Optional, Inject, Injectable, Self, SkipSelf, InjectMetadata, Host, HostMetadata, SkipSelfMetadata} from 'angular2/di'; import {bind, Injector, Binding, Optional, Inject, Injectable, Self, SkipSelf, InjectMetadata, Host, HostMetadata, SkipSelfMetadata} from 'angular2/di';
import {AppProtoView, AppView} from 'angular2/src/core/compiler/view';
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref'; import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
import {TemplateRef} from 'angular2/src/core/compiler/template_ref'; import {TemplateRef} from 'angular2/src/core/compiler/template_ref';
import {ElementRef} from 'angular2/src/core/compiler/element_ref'; import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {DynamicChangeDetector, ChangeDetectorRef, Parser, Lexer} from 'angular2/src/core/change_detection/change_detection'; import {DynamicChangeDetector, ChangeDetectorRef, Parser, Lexer} from 'angular2/src/core/change_detection/change_detection';
import {QueryList} from 'angular2/src/core/compiler/query_list'; import {QueryList} from 'angular2/src/core/compiler/query_list';
@proxy function createDummyView(detector = null) {
@IMPLEMENTS(AppView) var res = new SpyView();
class DummyView extends SpyObject { res.prop("changeDetector", detector);
changeDetector; res.prop("elementOffset", 0);
elementOffset: number; return res;
constructor() {
super(AppView);
this.changeDetector = null;
this.elementOffset = 0;
}
noSuchMethod(m) { return super.noSuchMethod(m); }
}
@proxy
@IMPLEMENTS(ElementRef)
class DummyElementRef extends SpyObject {
boundElementIndex: number = 0;
constructor() { super(ElementRef); }
noSuchMethod(m) { return super.noSuchMethod(m); }
} }
@Injectable() @Injectable()
@ -245,7 +229,7 @@ class TestNode extends TreeNode<TestNode> {
} }
export function main() { export function main() {
var defaultPreBuiltObjects = new PreBuiltObjects(null, <any>new DummyView(), <any>new DummyElementRef(), null); var defaultPreBuiltObjects = new PreBuiltObjects(null, <any>createDummyView(), <any>new SpyElementRef(), null);
// An injector with more than 10 bindings will switch to the dynamic strategy // An injector with more than 10 bindings will switch to the dynamic strategy
var dynamicBindings = []; var dynamicBindings = [];
@ -773,7 +757,7 @@ export function main() {
}); });
it("should instantiate directives that depend on pre built objects", () => { it("should instantiate directives that depend on pre built objects", () => {
var templateRef = new TemplateRef(<any>new DummyElementRef()); var templateRef = new TemplateRef(<any>new SpyElementRef());
var bindings = ListWrapper.concat([NeedsTemplateRef], extraBindings); var bindings = ListWrapper.concat([NeedsTemplateRef], extraBindings);
var inj = injector(bindings, null, false, new PreBuiltObjects(null, null, null, templateRef)); var inj = injector(bindings, null, false, new PreBuiltObjects(null, null, null, templateRef));
@ -987,24 +971,22 @@ export function main() {
it("should inject ChangeDetectorRef of the component's view into the component", () => { it("should inject ChangeDetectorRef of the component's view into the component", () => {
var cd = new DynamicChangeDetector(null, null, 0, [], [], null, [], [], [], null); var cd = new DynamicChangeDetector(null, null, 0, [], [], null, [], [], [], null);
var view = <any>new DummyView(); var view = <any>createDummyView();
var childView = new DummyView(); var childView = createDummyView(cd);
childView.changeDetector = cd;
view.spy('getNestedView').andReturn(childView); view.spy('getNestedView').andReturn(childView);
var binding = DirectiveBinding.createFromType(ComponentNeedsChangeDetectorRef, new ComponentMetadata()); var binding = DirectiveBinding.createFromType(ComponentNeedsChangeDetectorRef, new ComponentMetadata());
var inj = injector(ListWrapper.concat([binding], extraBindings), null, true, var inj = injector(ListWrapper.concat([binding], extraBindings), null, true,
new PreBuiltObjects(null, view, <any>new DummyElementRef(), null)); new PreBuiltObjects(null, view, <any>new SpyElementRef(), null));
expect(inj.get(ComponentNeedsChangeDetectorRef).changeDetectorRef).toBe(cd.ref); expect(inj.get(ComponentNeedsChangeDetectorRef).changeDetectorRef).toBe(cd.ref);
}); });
it("should inject ChangeDetectorRef of the containing component into directives", () => { it("should inject ChangeDetectorRef of the containing component into directives", () => {
var cd = new DynamicChangeDetector(null, null, 0, [], [], null, [], [], [], null); var cd = new DynamicChangeDetector(null, null, 0, [], [], null, [], [], [], null);
var view = <any>new DummyView(); var view = <any>createDummyView(cd);
view.changeDetector =cd;
var binding = DirectiveBinding.createFromType(DirectiveNeedsChangeDetectorRef, new DirectiveMetadata()); var binding = DirectiveBinding.createFromType(DirectiveNeedsChangeDetectorRef, new DirectiveMetadata());
var inj = injector(ListWrapper.concat([binding], extraBindings), null, false, var inj = injector(ListWrapper.concat([binding], extraBindings), null, false,
new PreBuiltObjects(null, view, <any>new DummyElementRef(), null)); new PreBuiltObjects(null, view, <any>new SpyElementRef(), null));
expect(inj.get(DirectiveNeedsChangeDetectorRef).changeDetectorRef).toBe(cd.ref); expect(inj.get(DirectiveNeedsChangeDetectorRef).changeDetectorRef).toBe(cd.ref);
}); });
@ -1015,7 +997,7 @@ export function main() {
}); });
it("should inject TemplateRef", () => { it("should inject TemplateRef", () => {
var templateRef = new TemplateRef(<any>new DummyElementRef()); var templateRef = new TemplateRef(<any>new SpyElementRef());
var inj = injector(ListWrapper.concat([NeedsTemplateRef], extraBindings), null, false, var inj = injector(ListWrapper.concat([NeedsTemplateRef], extraBindings), null, false,
new PreBuiltObjects(null, null, null, templateRef)); new PreBuiltObjects(null, null, null, templateRef));
@ -1065,7 +1047,7 @@ export function main() {
}) })
it('should contain PreBuiltObjects on the same injector', () => { it('should contain PreBuiltObjects on the same injector', () => {
var preBuiltObjects = new PreBuiltObjects(null, null, null, new TemplateRef(<any>new DummyElementRef())); var preBuiltObjects = new PreBuiltObjects(null, null, null, new TemplateRef(<any>new SpyElementRef()));
var inj = injector(ListWrapper.concat([ var inj = injector(ListWrapper.concat([
NeedsTemplateRefQuery NeedsTemplateRefQuery
], extraBindings), null, ], extraBindings), null,

View File

@ -8,12 +8,11 @@ import {
expect, expect,
iit, iit,
inject, inject,
it, it
SpyObject,
proxy
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {isBlank, IMPLEMENTS, stringify} from 'angular2/src/core/facade/lang'; import {SpyChangeDetection} from '../spies';
import {isBlank, stringify} from 'angular2/src/core/facade/lang';
import {MapWrapper} from 'angular2/src/core/facade/collection'; import {MapWrapper} from 'angular2/src/core/facade/collection';
import { import {
@ -53,7 +52,8 @@ export function main() {
beforeEach(() => { beforeEach(() => {
directiveResolver = new DirectiveResolver(); directiveResolver = new DirectiveResolver();
changeDetection = new ChangeDetectionSpy(); changeDetection = new SpyChangeDetection();
changeDetection.prop("generateDetectors", true);
protoViewFactory = new ProtoViewFactory(changeDetection); protoViewFactory = new ProtoViewFactory(changeDetection);
}); });
@ -254,14 +254,6 @@ function createRenderViewportElementBinder(nestedProtoView) {
return new RenderElementBinder({nestedProtoView: nestedProtoView}); return new RenderElementBinder({nestedProtoView: nestedProtoView});
} }
@proxy
@IMPLEMENTS(ChangeDetection)
class ChangeDetectionSpy extends SpyObject {
constructor() { super(ChangeDetection); }
noSuchMethod(m) { return super.noSuchMethod(m) }
get generateDetectors() { return true; }
}
@Component({selector: 'main-comp'}) @Component({selector: 'main-comp'})
class MainComponent { class MainComponent {
} }

View File

@ -11,16 +11,12 @@ import {
inject, inject,
beforeEachBindings, beforeEachBindings,
it, it,
xit, xit
SpyObject,
proxy
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang'; import {SpyView, SpyAppViewManager} from '../spies';
import {AppView, AppViewContainer} from 'angular2/src/core/compiler/view'; import {AppView, AppViewContainer} from 'angular2/src/core/compiler/view';
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref'; import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
import {ElementRef} from 'angular2/src/core/compiler/element_ref'; import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {ViewRef} from 'angular2/src/core/compiler/view_ref'; import {ViewRef} from 'angular2/src/core/compiler/view_ref';
@ -35,8 +31,9 @@ export function main() {
function createViewContainer() { return new ViewContainerRef(viewManager, location); } function createViewContainer() { return new ViewContainerRef(viewManager, location); }
beforeEach(() => { beforeEach(() => {
viewManager = new AppViewManagerSpy(); viewManager = new SpyAppViewManager();
view = new AppViewSpy(); view = new SpyView();
view.prop("viewContainers", [null]);
location = new ElementRef(new ViewRef(view), 0, 0, null); location = new ElementRef(new ViewRef(view), 0, 0, null);
}); });
@ -50,8 +47,8 @@ export function main() {
it('should return the size of the underlying AppViewContainer', () => { it('should return the size of the underlying AppViewContainer', () => {
var vc = createViewContainer(); var vc = createViewContainer();
var appVc = new AppViewContainer(); var appVc = new AppViewContainer();
view.viewContainers = [appVc]; view.prop("viewContainers", [appVc]);
appVc.views = [<any>new AppViewSpy()]; appVc.views = [<any>new SpyView()];
expect(vc.length).toBe(1); expect(vc.length).toBe(1);
}); });
@ -61,18 +58,3 @@ export function main() {
}); });
} }
@proxy
@IMPLEMENTS(AppView)
class AppViewSpy extends SpyObject {
viewContainers: AppViewContainer[] = [null];
constructor() { super(AppView); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}
@proxy
@IMPLEMENTS(AppViewManager)
class AppViewManagerSpy extends SpyObject {
constructor() { super(AppViewManager); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}

View File

@ -11,12 +11,11 @@ import {
inject, inject,
beforeEachBindings, beforeEachBindings,
it, it,
xit, xit
SpyObject,
proxy
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {SpyRenderer, SpyAppViewPool, SpyAppViewListener} from '../spies';
import {Injector, bind} from 'angular2/di'; import {Injector, bind} from 'angular2/di';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import { import {
AppProtoView, AppProtoView,
@ -38,8 +37,6 @@ import {
} from 'angular2/src/core/render/api'; } from 'angular2/src/core/render/api';
import {AppViewManager} from 'angular2/src/core/compiler/view_manager'; import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
import {AppViewManagerUtils} from 'angular2/src/core/compiler/view_manager_utils'; import {AppViewManagerUtils} from 'angular2/src/core/compiler/view_manager_utils';
import {AppViewListener} from 'angular2/src/core/compiler/view_listener';
import {AppViewPool} from 'angular2/src/core/compiler/view_pool';
import { import {
createHostPv, createHostPv,
@ -506,24 +503,3 @@ export function main() {
}); });
}); });
} }
@proxy
@IMPLEMENTS(Renderer)
class SpyRenderer extends SpyObject {
constructor() { super(Renderer); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}
@proxy
@IMPLEMENTS(AppViewPool)
class SpyAppViewPool extends SpyObject {
constructor() { super(AppViewPool); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}
@proxy
@IMPLEMENTS(AppViewListener)
class SpyAppViewListener extends SpyObject {
constructor() { super(AppViewListener); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}

View File

@ -12,15 +12,20 @@ import {
beforeEachBindings, beforeEachBindings,
it, it,
xit, xit,
SpyObject, Log,
SpyChangeDetector, SpyObject
SpyProtoChangeDetector,
proxy,
Log
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {
SpyChangeDetector,
SpyProtoChangeDetector,
SpyProtoElementInjector,
SpyElementInjector,
SpyPreBuiltObjects
} from '../spies';
import {Injector, bind} from 'angular2/di'; import {Injector, bind} from 'angular2/di';
import {IMPLEMENTS, isBlank, isPresent} from 'angular2/src/core/facade/lang'; import {isBlank, isPresent} from 'angular2/src/core/facade/lang';
import {MapWrapper, ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection'; import {MapWrapper, ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {AppProtoView, AppView, AppProtoViewMergeMapping} from 'angular2/src/core/compiler/view'; import {AppProtoView, AppView, AppProtoViewMergeMapping} from 'angular2/src/core/compiler/view';
@ -231,9 +236,9 @@ export function createInjector() {
} }
function createElementInjector(parent = null) { function createElementInjector(parent = null) {
var host = new SpyElementInjector(null); var host = new SpyElementInjector();
var elementInjector = new SpyElementInjector(parent); var elementInjector = new SpyElementInjector();
return SpyObject.stub(elementInjector, var res = SpyObject.stub(elementInjector,
{ {
'isExportingComponent': false, 'isExportingComponent': false,
'isExportingElement': false, 'isExportingElement': false,
@ -243,10 +248,14 @@ function createElementInjector(parent = null) {
'getHost': host 'getHost': host
}, },
{}); {});
res.prop('parent', parent);
return res;
} }
export function createProtoElInjector(parent: ProtoElementInjector = null): ProtoElementInjector { export function createProtoElInjector(parent: ProtoElementInjector = null): ProtoElementInjector {
var pei = new SpyProtoElementInjector(parent); var pei = new SpyProtoElementInjector();
pei.prop("parent", parent);
pei.prop("index", 0);
pei.spy('instantiate').andCallFake((parentEli) => createElementInjector(parentEli)); pei.spy('instantiate').andCallFake((parentEli) => createElementInjector(parentEli));
return <any>pei; return <any>pei;
} }
@ -353,32 +362,3 @@ export function createEmbeddedPv(binders: ElementBinder[] = null) {
@Component({selector: 'someComponent'}) @Component({selector: 'someComponent'})
class SomeComponent { class SomeComponent {
} }
@proxy
@IMPLEMENTS(ProtoElementInjector)
class SpyProtoElementInjector extends SpyObject {
index: number;
constructor(public parent: ProtoElementInjector) { super(ProtoElementInjector); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}
@proxy
@IMPLEMENTS(ElementInjector)
class SpyElementInjector extends SpyObject {
constructor(public parent: ElementInjector) { super(ElementInjector); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}
@proxy
@IMPLEMENTS(PreBuiltObjects)
class SpyPreBuiltObjects extends SpyObject {
constructor() { super(PreBuiltObjects); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}
@proxy
@IMPLEMENTS(Injector)
class SpyInjector extends SpyObject {
constructor() { super(Injector); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}

View File

@ -1,13 +1,6 @@
import {isBlank, BaseException, stringify} from 'angular2/src/core/facade/lang'; import {isBlank, BaseException, stringify} from 'angular2/src/core/facade/lang';
import { import {describe, ddescribe, it, iit, expect, beforeEach} from 'angular2/test_lib';
describe, import {SpyDependencyProvider} from '../spies';
ddescribe,
it,
iit,
expect,
beforeEach,
SpyDependencyProvider
} from 'angular2/test_lib';
import { import {
Injector, Injector,
ProtoInjector, ProtoInjector,

View File

@ -1,9 +1,15 @@
library angular2.test.directives.observable_list_iterable_diff_spec; library angular2.test.directives.observable_list_iterable_diff_spec;
import 'package:angular2/test_lib.dart'; import 'package:angular2/test_lib.dart';
import 'package:angular2/change_detection.dart';
import 'package:observe/observe.dart' show ObservableList; import 'package:observe/observe.dart' show ObservableList;
import 'package:angular2/src/core/directives/observable_list_diff.dart'; import 'package:angular2/src/core/directives/observable_list_diff.dart';
@proxy
class SpyChangeDetectorRef extends SpyObject implements ChangeDetectorRef {
noSuchMethod(m) => super.noSuchMethod(m);
}
main() { main() {
describe('ObservableListDiff', () { describe('ObservableListDiff', () {
var factory, changeDetectorRef; var factory, changeDetectorRef;

View File

@ -11,11 +11,10 @@ import {
AsyncTestCompleter, AsyncTestCompleter,
fakeAsync, fakeAsync,
tick, tick,
inject, inject
SpyChangeDetector,
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {LifeCycle} from 'angular2/core'; import {LifeCycle} from 'angular2/core';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang'; import {SpyChangeDetector} from '../spies';
export function main() { export function main() {
describe("LifeCycle", () => { describe("LifeCycle", () => {

View File

@ -1,5 +1,5 @@
import {describe, beforeEach, it, xit, expect, iit, ddescribe, el} from 'angular2/test_lib'; import {describe, beforeEach, it, xit, expect, iit, ddescribe, el} from 'angular2/test_lib';
import {isPresent, isBlank, assertionsEnabled, IMPLEMENTS} from 'angular2/src/core/facade/lang'; import {isPresent, isBlank, assertionsEnabled} from 'angular2/src/core/facade/lang';
import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection'; import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {DOM} from 'angular2/src/core/dom/dom_adapter'; import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {DirectiveParser} from 'angular2/src/core/render/dom/compiler/directive_parser'; import {DirectiveParser} from 'angular2/src/core/render/dom/compiler/directive_parser';

View File

@ -1,7 +1,7 @@
import {describe, beforeEach, it, expect, iit, ddescribe, el} from 'angular2/test_lib'; import {describe, beforeEach, it, expect, iit, ddescribe, el} from 'angular2/test_lib';
import {ListWrapper, List, MapWrapper} from 'angular2/src/core/facade/collection'; import {ListWrapper, List, MapWrapper} from 'angular2/src/core/facade/collection';
import {DOM} from 'angular2/src/core/dom/dom_adapter'; import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {isPresent, NumberWrapper, StringWrapper, IMPLEMENTS} from 'angular2/src/core/facade/lang'; import {isPresent, NumberWrapper, StringWrapper} from 'angular2/src/core/facade/lang';
import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline'; import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline';
import {CompileElement} from 'angular2/src/core/render/dom/compiler/compile_element'; import {CompileElement} from 'angular2/src/core/render/dom/compiler/compile_element';

View File

@ -1,5 +1,4 @@
import {describe, beforeEach, it, expect, iit, ddescribe, el} from 'angular2/test_lib'; import {describe, beforeEach, it, expect, iit, ddescribe, el} from 'angular2/test_lib';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import {PropertyBindingParser} from 'angular2/src/core/render/dom/compiler/property_binding_parser'; import {PropertyBindingParser} from 'angular2/src/core/render/dom/compiler/property_binding_parser';
import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline'; import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline';
import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection'; import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';

View File

@ -7,16 +7,14 @@ import {
iit, iit,
xit, xit,
expect, expect,
SpyObject, SpyObject
proxy
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {SpyElementRef, SpyDomAdapter} from '../spies';
import {DOM, DomAdapter} from 'angular2/src/core/dom/dom_adapter'; import {DOM, DomAdapter} from 'angular2/src/core/dom/dom_adapter';
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {Ruler, Rectangle} from 'angular2/src/core/services/ruler'; import {Ruler, Rectangle} from 'angular2/src/core/services/ruler';
import {createRectangle} from './rectangle_mock'; import {createRectangle} from './rectangle_mock';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
function assertDimensions(rect: Rectangle, left, right, top, bottom, width, height) { function assertDimensions(rect: Rectangle, left, right, top, bottom, width, height) {
expect(rect.left).toEqual(left); expect(rect.left).toEqual(left);
@ -33,7 +31,6 @@ export function main() {
it('should allow measuring ElementRefs', inject([AsyncTestCompleter], (async) => { it('should allow measuring ElementRefs', inject([AsyncTestCompleter], (async) => {
var ruler = new Ruler(SpyObject.stub( var ruler = new Ruler(SpyObject.stub(
new SpyDomAdapter(), {'getBoundingClientRect': createRectangle(10, 20, 200, 100)})); new SpyDomAdapter(), {'getBoundingClientRect': createRectangle(10, 20, 200, 100)}));
var elRef = <any>new SpyElementRef(); var elRef = <any>new SpyElementRef();
ruler.measure(elRef).then((rect) => { ruler.measure(elRef).then((rect) => {
assertDimensions(rect, 10, 210, 20, 120, 200, 100); assertDimensions(rect, 10, 210, 20, 120, 200, 100);
@ -46,7 +43,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => { inject([AsyncTestCompleter], (async) => {
var ruler = new Ruler(DOM); var ruler = new Ruler(DOM);
var elRef = <any>new SpyElementRef(); var elRef = <any>new SpyElementRef();
elRef.nativeElement = DOM.createElement('div'); elRef.prop("nativeElement", DOM.createElement('div'));
ruler.measure(elRef).then((rect) => { ruler.measure(elRef).then((rect) => {
// here we are using an element created in a doc fragment so all the measures will come // here we are using an element created in a doc fragment so all the measures will come
// back as 0 // back as 0
@ -57,18 +54,3 @@ export function main() {
}); });
} }
@proxy
@IMPLEMENTS(ElementRef)
class SpyElementRef extends SpyObject {
nativeElement;
constructor() { super(ElementRef); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}
@proxy
@IMPLEMENTS(DomAdapter)
class SpyDomAdapter extends SpyObject {
constructor() { super(DomAdapter); }
noSuchMethod(m) { return super.noSuchMethod(m) }
}

View File

@ -0,0 +1,105 @@
library core.spies;
import 'package:angular2/di.dart';
import 'package:angular2/src/core/change_detection/change_detection.dart';
import 'package:angular2/src/core/render/api.dart';
import 'package:angular2/src/core/compiler/directive_resolver.dart';
import 'package:angular2/src/core/compiler/view.dart';
import 'package:angular2/src/core/compiler/element_ref.dart';
import 'package:angular2/src/core/compiler/view_manager.dart';
import 'package:angular2/src/core/compiler/view_pool.dart';
import 'package:angular2/src/core/compiler/view_listener.dart';
import 'package:angular2/src/core/compiler/element_injector.dart';
import 'package:angular2/src/core/dom/dom_adapter.dart';
import 'package:angular2/test_lib.dart';
@proxy
class SpyDependencyProvider extends SpyObject implements DependencyProvider {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyChangeDetection extends SpyObject implements ChangeDetection {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyChangeDetector extends SpyObject implements ChangeDetector {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyProtoChangeDetector extends SpyObject implements ProtoChangeDetector {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyIterableDifferFactory extends SpyObject
implements IterableDifferFactory {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyInjector extends SpyObject implements Injector {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyRenderCompiler extends SpyObject implements RenderCompiler {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyDirectiveResolver extends SpyObject implements DirectiveResolver {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyView extends SpyObject implements AppView {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyElementRef extends SpyObject implements ElementRef {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyAppViewManager extends SpyObject implements AppViewManager {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyRenderer extends SpyObject implements Renderer {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyAppViewPool extends SpyObject implements AppViewPool {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyAppViewListener extends SpyObject implements AppViewListener {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyProtoElementInjector extends SpyObject implements ProtoElementInjector {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyElementInjector extends SpyObject implements ElementInjector {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyPreBuiltObjects extends SpyObject implements PreBuiltObjects {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyDomAdapter extends SpyObject implements DomAdapter {
noSuchMethod(m) => super.noSuchMethod(m);
}

View File

@ -0,0 +1,90 @@
import {
ChangeDetection,
ChangeDetector,
ChangeDetectorRef,
ProtoChangeDetector,
DynamicChangeDetector
} from 'angular2/src/core/change_detection/change_detection';
import {RenderCompiler, Renderer} from 'angular2/src/core/render/api';
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
import {AppView} from 'angular2/src/core/compiler/view';
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
import {AppViewPool} from 'angular2/src/core/compiler/view_pool';
import {AppViewListener} from 'angular2/src/core/compiler/view_listener';
import {DomAdapter} from 'angular2/src/core/dom/dom_adapter';
import {ClientMessageBroker} from 'angular2/src/web_workers/shared/client_message_broker';
import {
ElementInjector,
PreBuiltObjects,
ProtoElementInjector
} from 'angular2/src/core/compiler/element_injector';
import {SpyObject, proxy} from 'angular2/test_lib';
export class SpyDependencyProvider extends SpyObject {}
export class SpyChangeDetection extends SpyObject {
constructor() { super(ChangeDetection); }
}
export class SpyChangeDetector extends SpyObject {
constructor() { super(DynamicChangeDetector); }
}
export class SpyProtoChangeDetector extends SpyObject {
constructor() { super(DynamicChangeDetector); }
}
export class SpyIterableDifferFactory extends SpyObject {}
export class SpyRenderCompiler extends SpyObject {
constructor() { super(RenderCompiler); }
}
export class SpyDirectiveResolver extends SpyObject {
constructor() { super(DirectiveResolver); }
}
export class SpyView extends SpyObject {
constructor() { super(AppView); }
}
export class SpyElementRef extends SpyObject {
constructor() { super(ElementRef); }
}
export class SpyAppViewManager extends SpyObject {
constructor() { super(AppViewManager); }
}
export class SpyRenderer extends SpyObject {
constructor() { super(Renderer); }
}
export class SpyAppViewPool extends SpyObject {
constructor() { super(AppViewPool); }
}
export class SpyAppViewListener extends SpyObject {
constructor() { super(AppViewListener); }
}
export class SpyProtoElementInjector extends SpyObject {
constructor() { super(ProtoElementInjector); }
}
export class SpyElementInjector extends SpyObject {
constructor() { super(ElementInjector); }
}
export class SpyPreBuiltObjects extends SpyObject {
constructor() { super(PreBuiltObjects); }
}
export class SpyDomAdapter extends SpyObject {
constructor() { super(DomAdapter); }
}

View File

@ -8,12 +8,12 @@ import {
beforeEach, beforeEach,
afterEach, afterEach,
AsyncTestCompleter, AsyncTestCompleter,
SpyChangeDetectorRef,
inject, inject,
SpyObject SpyObject
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {SpyChangeDetectorRef} from './spies';
import {IMPLEMENTS, isBlank} from 'angular2/src/core/facade/lang'; import {isBlank} from 'angular2/src/core/facade/lang';
import {WrappedValue} from 'angular2/change_detection'; import {WrappedValue} from 'angular2/change_detection';
import {AsyncPipe} from 'angular2/pipes'; import {AsyncPipe} from 'angular2/pipes';
import { import {

View File

@ -0,0 +1,9 @@
library pipes.spies;
import 'package:angular2/src/core/change_detection/change_detection.dart';
import 'package:angular2/test_lib.dart';
@proxy
class SpyChangeDetectorRef extends SpyObject implements ChangeDetectorRef {
noSuchMethod(m) => super.noSuchMethod(m);
}

View File

@ -0,0 +1,7 @@
import {ChangeDetectorRef} from 'angular2/src/core/change_detection/change_detection';
import {SpyObject, proxy} from 'angular2/test_lib';
export class SpyChangeDetectorRef extends SpyObject {
constructor() { super(ChangeDetectorRef); }
}

View File

@ -17,7 +17,7 @@ import {
By By
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {IMPLEMENTS, NumberWrapper} from 'angular2/src/core/facade/lang'; import {NumberWrapper} from 'angular2/src/core/facade/lang';
import {bind, Component, View} from 'angular2/angular2'; import {bind, Component, View} from 'angular2/angular2';

View File

@ -12,12 +12,10 @@ import {
it, it,
xit, xit,
TestComponentBuilder, TestComponentBuilder,
proxy,
SpyObject,
By By
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang'; import {SpyRouter, SpyLocation} from './spies';
import {bind, Component, View} from 'angular2/angular2'; import {bind, Component, View} from 'angular2/angular2';
@ -98,28 +96,14 @@ class UserCmp {
class TestComponent { class TestComponent {
} }
@proxy
@IMPLEMENTS(Location)
class DummyLocation extends SpyObject {
noSuchMethod(m) { return super.noSuchMethod(m) }
}
function makeDummyLocation() { function makeDummyLocation() {
var dl = new DummyLocation(); var dl = new SpyLocation();
dl.spy('normalizeAbsolutely').andCallFake((url) => url); dl.spy('normalizeAbsolutely').andCallFake((url) => url);
return dl; return dl;
} }
@proxy
@IMPLEMENTS(Router)
class DummyRouter extends SpyObject {
noSuchMethod(m) { return super.noSuchMethod(m) }
}
function makeDummyRouter() { function makeDummyRouter() {
var dr = new DummyRouter(); var dr = new SpyRouter();
dr.spy('generate').andCallFake((routeParams) => dummyInstruction); dr.spy('generate').andCallFake((routeParams) => dummyInstruction);
dr.spy('navigateInstruction'); dr.spy('navigateInstruction');
return dr; return dr;

View File

@ -8,16 +8,15 @@ import {
expect, expect,
inject, inject,
beforeEach, beforeEach,
beforeEachBindings, beforeEachBindings
SpyObject
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {IMPLEMENTS, Type} from 'angular2/src/core/facade/lang'; import {SpyRouterOutlet} from './spies';
import {Type} from 'angular2/src/core/facade/lang';
import {Promise, PromiseWrapper, ObservableWrapper} from 'angular2/src/core/facade/async'; import {Promise, PromiseWrapper, ObservableWrapper} from 'angular2/src/core/facade/async';
import {ListWrapper} from 'angular2/src/core/facade/collection'; import {ListWrapper} from 'angular2/src/core/facade/collection';
import {Router, RootRouter} from 'angular2/src/router/router'; import {Router, RootRouter} from 'angular2/src/router/router';
import {Pipeline} from 'angular2/src/router/pipeline'; import {Pipeline} from 'angular2/src/router/pipeline';
import {RouterOutlet} from 'angular2/src/router/router_outlet';
import {SpyLocation} from 'angular2/src/mock/location_mock'; import {SpyLocation} from 'angular2/src/mock/location_mock';
import {Location} from 'angular2/src/router/location'; import {Location} from 'angular2/src/router/location';
import {stringifyInstruction} from 'angular2/src/router/instruction'; import {stringifyInstruction} from 'angular2/src/router/instruction';
@ -203,12 +202,6 @@ function loader(): Promise<Type> {
return PromiseWrapper.resolve(DummyComponent); return PromiseWrapper.resolve(DummyComponent);
} }
@proxy
@IMPLEMENTS(RouterOutlet)
class DummyOutlet extends SpyObject {
noSuchMethod(m) { return super.noSuchMethod(m) }
}
class DummyComponent {} class DummyComponent {}
@RouteConfig([new Route({path: '/second', component: DummyComponent, as: 'secondCmp'})]) @RouteConfig([new Route({path: '/second', component: DummyComponent, as: 'secondCmp'})])
@ -216,7 +209,7 @@ class DummyParentComp {
} }
function makeDummyOutlet() { function makeDummyOutlet() {
var ref = new DummyOutlet(); var ref = new SpyRouterOutlet();
ref.spy('canActivate').andCallFake((_) => PromiseWrapper.resolve(true)); ref.spy('canActivate').andCallFake((_) => PromiseWrapper.resolve(true));
ref.spy('canReuse').andCallFake((_) => PromiseWrapper.resolve(false)); ref.spy('canReuse').andCallFake((_) => PromiseWrapper.resolve(false));
ref.spy('canDeactivate').andCallFake((_) => PromiseWrapper.resolve(true)); ref.spy('canDeactivate').andCallFake((_) => PromiseWrapper.resolve(true));

View File

@ -0,0 +1,19 @@
library router.spies;
import 'package:angular2/router.dart';
import 'package:angular2/test_lib.dart';
@proxy
class SpyLocation extends SpyObject implements Location {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyRouter extends SpyObject implements Router {
noSuchMethod(m) => super.noSuchMethod(m);
}
@proxy
class SpyRouterOutlet extends SpyObject implements RouterOutlet {
noSuchMethod(m) => super.noSuchMethod(m);
}

View File

@ -0,0 +1,14 @@
import {Router, RouterOutlet, Location} from 'angular2/router';
import {SpyObject, proxy} from 'angular2/test_lib';
export class SpyRouter extends SpyObject {
constructor() { super(Router); }
}
export class SpyRouterOutlet extends SpyObject {
constructor() { super(RouterOutlet); }
}
export class SpyLocation extends SpyObject {
constructor() { super(Location); }
}

View File

@ -13,7 +13,7 @@ import {
import {DOM} from 'angular2/src/core/dom/dom_adapter'; import {DOM} from 'angular2/src/core/dom/dom_adapter';
import {MapWrapper} from 'angular2/src/core/facade/collection'; import {MapWrapper} from 'angular2/src/core/facade/collection';
import {IMPLEMENTS, RegExpWrapper} from 'angular2/src/core/facade/lang'; import {RegExpWrapper} from 'angular2/src/core/facade/lang';
class TestObj { class TestObj {
prop; prop;
@ -22,8 +22,6 @@ class TestObj {
someComplexFunc(a) { return a; } someComplexFunc(a) { return a; }
} }
@proxy
@IMPLEMENTS(TestObj)
class SpyTestObj extends SpyObject { class SpyTestObj extends SpyObject {
constructor() { super(TestObj); } constructor() { super(TestObj); }
noSuchMethod(m) { return super.noSuchMethod(m) } noSuchMethod(m) { return super.noSuchMethod(m) }
@ -89,11 +87,6 @@ export function main() {
beforeEach(() => { spyObj = <any>new SpyTestObj(); }); beforeEach(() => { spyObj = <any>new SpyTestObj(); });
it("should pass the runtime check", () => {
var t: TestObj = spyObj;
expect(t).toBeDefined();
});
it("should return a new spy func with no calls", it("should return a new spy func with no calls",
() => { expect(spyObj.spy("someFunc")).not.toHaveBeenCalled(); }); () => { expect(spyObj.spy("someFunc")).not.toHaveBeenCalled(); });

View File

@ -10,7 +10,6 @@ import {
SpyObject, SpyObject,
proxy proxy
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import {Serializer} from 'angular2/src/web_workers/shared/serializer'; import {Serializer} from 'angular2/src/web_workers/shared/serializer';
import {NgZone} from 'angular2/src/core/zone/ng_zone'; import {NgZone} from 'angular2/src/core/zone/ng_zone';
import {ON_WEB_WORKER} from 'angular2/src/web_workers/shared/api'; import {ON_WEB_WORKER} from 'angular2/src/web_workers/shared/api';

View File

@ -0,0 +1,11 @@
library web_workers.spies;
import 'package:angular2/src/web_workers/shared/client_message_broker.dart';
import 'package:angular2/test_lib.dart';
@proxy
class SpyMessageBroker extends SpyObject implements ClientMessageBroker {
noSuchMethod(m) => super.noSuchMethod(m);
}

View File

@ -0,0 +1,7 @@
import {ClientMessageBroker} from 'angular2/src/web_workers/shared/client_message_broker';
import {SpyObject, proxy} from 'angular2/test_lib';
export class SpyMessageBroker extends SpyObject {
constructor() { super(ClientMessageBroker); }
}

View File

@ -6,11 +6,10 @@ import {
expect, expect,
beforeEach, beforeEach,
createTestInjector, createTestInjector,
beforeEachBindings, beforeEachBindings
SpyObject,
proxy
} from 'angular2/test_lib'; } from 'angular2/test_lib';
import {IMPLEMENTS, Type} from 'angular2/src/core/facade/lang'; import {SpyMessageBroker} from './spies';
import {Type} from 'angular2/src/core/facade/lang';
import { import {
ClientMessageBroker, ClientMessageBroker,
UiArguments, UiArguments,
@ -44,13 +43,6 @@ export function main() {
}); });
} }
@proxy
@IMPLEMENTS(ClientMessageBroker)
class SpyMessageBroker extends SpyObject {
constructor() { super(ClientMessageBroker); }
noSuchMethod(m) { return super.noSuchMethod(m); }
}
class MockMessageBrokerFactory extends ClientMessageBrokerFactory { class MockMessageBrokerFactory extends ClientMessageBrokerFactory {
constructor(private _messageBroker: ClientMessageBroker) { super(null, null); } constructor(private _messageBroker: ClientMessageBroker) { super(null, null); }
createMessageBroker(channel: string) { return this._messageBroker; } createMessageBroker(channel: string) { return this._messageBroker; }

View File

@ -1,5 +1,4 @@
// Test library and utilities for internal use. // Test library and utilities for internal use.
export * from './test'; export * from './test';
export * from './src/test_lib/spies';
export * from './src/test_lib/utils'; export * from './src/test_lib/utils';
export * from './src/test_lib/fake_async'; export * from './src/test_lib/fake_async';

View File

@ -1,4 +1,4 @@
import {IMPLEMENTS, print} from 'angular2/src/core/facade/lang'; import {print} from 'angular2/src/core/facade/lang';
import {UrlResolver} from 'angular2/src/core/services/url_resolver'; import {UrlResolver} from 'angular2/src/core/services/url_resolver';
import { import {
isPresent, isPresent,