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) {
return expr;
}

View File

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

View File

@ -71,13 +71,6 @@ export function ABSTRACT(): ClassDecorator {
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 {
return obj !== undefined && obj !== null;
}

View File

@ -5,15 +5,14 @@ import {ReadyStates} from '../enums';
import {Connection, ConnectionBackend} from '../interfaces';
import {ObservableWrapper, EventEmitter} from 'angular2/src/core/facade/async';
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.
*
**/
@IMPLEMENTS(Connection)
export class MockConnection {
export class MockConnection implements Connection {
// TODO Name `readyState` should change to be more generic, and states could be made to be more
// descriptive than XHR states.
/**
@ -130,8 +129,7 @@ export class MockConnection {
* This method only exists in the mock implementation, not in real Backends.
**/
@Injectable()
@IMPLEMENTS(ConnectionBackend)
export class MockBackend {
export class MockBackend implements ConnectionBackend {
/**
* {@link EventEmitter}
* 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 {List, ListWrapper} from 'angular2/src/core/facade/collection';
import {Location} from 'angular2/src/router/location';
@proxy
@IMPLEMENTS(Location)
export class SpyLocation extends SpyObject {
urlChanges: List<string>;
_path: string;
_subject: EventEmitter;
_baseHref: string;
constructor() {
super();
this._path = '';
this.urlChanges = [];
this._subject = new EventEmitter();
this._baseHref = '';
}
export class SpyLocation implements Location {
urlChanges: List<string> = [];
_path: string = '';
_subject: EventEmitter = new EventEmitter();
_baseHref: string = '';
setInitialPath(url: string) { this._path = url; }
@ -54,5 +40,7 @@ export class SpyLocation extends SpyObject {
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()
export class Location {
private _subject: EventEmitter = new EventEmitter();
private _baseHref: string;
_subject: EventEmitter = new EventEmitter();
_baseHref: string;
constructor(public _platformStrategy: LocationStrategy,
constructor(public platformStrategy: LocationStrategy,
@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)) {
throw new BaseException(
@ -31,48 +31,31 @@ export class Location {
}
this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref));
this._platformStrategy.onPopState((_) => this._onPopState(_));
this.platformStrategy.onPopState(
(_) => { ObservableWrapper.callNext(this._subject, {'url': this.path(), 'pop': true}); });
}
_onPopState(_): void {
ObservableWrapper.callNext(this._subject, {'url': this.path(), 'pop': true});
}
path(): string { return this.normalize(this._platformStrategy.path()); }
path(): string { return this.normalize(this.platformStrategy.path()); }
normalize(url: string): string {
return stripTrailingSlash(this._stripBaseHref(stripIndexHtml(url)));
return stripTrailingSlash(_stripBaseHref(this._baseHref, stripIndexHtml(url)));
}
normalizeAbsolutely(url: string): string {
if (!url.startsWith('/')) {
url = '/' + url;
}
return stripTrailingSlash(this._addBaseHref(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;
return stripTrailingSlash(_addBaseHref(this._baseHref, url));
}
go(url: string): void {
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,
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 {
if (/\/index.html$/g.test(url)) {

View File

@ -15,7 +15,6 @@ import {
List,
ListWrapper
} from 'angular2/src/core/facade/collection';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import {RouteHandler} from './route_handler';
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) =>
_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]) {
if (object is! SpyObject) {
overrides = config;

View File

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

View File

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

View File

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

View File

@ -8,11 +8,9 @@ import {
expect,
iit,
inject,
it,
SpyObject,
proxy
it
} from 'angular2/test_lib';
import {SpyRenderCompiler, SpyDirectiveResolver} from '../spies';
import {
List,
ListWrapper,
@ -20,14 +18,7 @@ import {
MapWrapper,
StringMapWrapper
} from 'angular2/src/core/facade/collection';
import {
IMPLEMENTS,
Type,
isBlank,
stringify,
isPresent,
isArray
} from 'angular2/src/core/facade/lang';
import {Type, isBlank, stringify, isPresent, isArray} from 'angular2/src/core/facade/lang';
import {PromiseCompleter, PromiseWrapper, Promise} from 'angular2/src/core/facade/async';
import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
@ -58,7 +49,6 @@ import {
RenderElementBinder
} from 'angular2/src/core/render/api';
// 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';
@ -718,20 +708,6 @@ class DirectiveWithAttributes {
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 {
_cmpViews: Map<Type, ViewMetadata> = new Map();

View File

@ -10,14 +10,13 @@ import {
xdescribe,
expect,
beforeEach,
SpyObject,
proxy,
inject,
AsyncTestCompleter,
el,
containsRegexp
} 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 {
ListWrapper,
MapWrapper,
@ -41,32 +40,17 @@ import {
LifecycleEvent
} from 'angular2/metadata';
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 {TemplateRef} from 'angular2/src/core/compiler/template_ref';
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {DynamicChangeDetector, ChangeDetectorRef, Parser, Lexer} from 'angular2/src/core/change_detection/change_detection';
import {QueryList} from 'angular2/src/core/compiler/query_list';
@proxy
@IMPLEMENTS(AppView)
class DummyView extends SpyObject {
changeDetector;
elementOffset: number;
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); }
function createDummyView(detector = null) {
var res = new SpyView();
res.prop("changeDetector", detector);
res.prop("elementOffset", 0);
return res;
}
@Injectable()
@ -245,7 +229,7 @@ class TestNode extends TreeNode<TestNode> {
}
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
var dynamicBindings = [];
@ -773,7 +757,7 @@ export function main() {
});
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 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", () => {
var cd = new DynamicChangeDetector(null, null, 0, [], [], null, [], [], [], null);
var view = <any>new DummyView();
var childView = new DummyView();
childView.changeDetector = cd;
var view = <any>createDummyView();
var childView = createDummyView(cd);
view.spy('getNestedView').andReturn(childView);
var binding = DirectiveBinding.createFromType(ComponentNeedsChangeDetectorRef, new ComponentMetadata());
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);
});
it("should inject ChangeDetectorRef of the containing component into directives", () => {
var cd = new DynamicChangeDetector(null, null, 0, [], [], null, [], [], [], null);
var view = <any>new DummyView();
view.changeDetector =cd;
var view = <any>createDummyView(cd);
var binding = DirectiveBinding.createFromType(DirectiveNeedsChangeDetectorRef, new DirectiveMetadata());
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);
});
@ -1015,7 +997,7 @@ export function main() {
});
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,
new PreBuiltObjects(null, null, null, templateRef));
@ -1065,7 +1047,7 @@ export function main() {
})
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([
NeedsTemplateRefQuery
], extraBindings), null,

View File

@ -8,12 +8,11 @@ import {
expect,
iit,
inject,
it,
SpyObject,
proxy
it
} 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 {
@ -53,7 +52,8 @@ export function main() {
beforeEach(() => {
directiveResolver = new DirectiveResolver();
changeDetection = new ChangeDetectionSpy();
changeDetection = new SpyChangeDetection();
changeDetection.prop("generateDetectors", true);
protoViewFactory = new ProtoViewFactory(changeDetection);
});
@ -254,14 +254,6 @@ function createRenderViewportElementBinder(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'})
class MainComponent {
}

View File

@ -11,16 +11,12 @@ import {
inject,
beforeEachBindings,
it,
xit,
SpyObject,
proxy
xit
} 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 {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 {ViewRef} from 'angular2/src/core/compiler/view_ref';
@ -35,8 +31,9 @@ export function main() {
function createViewContainer() { return new ViewContainerRef(viewManager, location); }
beforeEach(() => {
viewManager = new AppViewManagerSpy();
view = new AppViewSpy();
viewManager = new SpyAppViewManager();
view = new SpyView();
view.prop("viewContainers", [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', () => {
var vc = createViewContainer();
var appVc = new AppViewContainer();
view.viewContainers = [appVc];
appVc.views = [<any>new AppViewSpy()];
view.prop("viewContainers", [appVc]);
appVc.views = [<any>new SpyView()];
expect(vc.length).toBe(1);
});
@ -60,19 +57,4 @@ export function main() {
// TODO: add missing tests here!
});
}
@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,
beforeEachBindings,
it,
xit,
SpyObject,
proxy
xit
} from 'angular2/test_lib';
import {SpyRenderer, SpyAppViewPool, SpyAppViewListener} from '../spies';
import {Injector, bind} from 'angular2/di';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import {
AppProtoView,
@ -38,8 +37,6 @@ import {
} from 'angular2/src/core/render/api';
import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
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 {
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,
it,
xit,
SpyObject,
SpyChangeDetector,
SpyProtoChangeDetector,
proxy,
Log
Log,
SpyObject
} from 'angular2/test_lib';
import {
SpyChangeDetector,
SpyProtoChangeDetector,
SpyProtoElementInjector,
SpyElementInjector,
SpyPreBuiltObjects
} from '../spies';
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 {AppProtoView, AppView, AppProtoViewMergeMapping} from 'angular2/src/core/compiler/view';
@ -231,22 +236,26 @@ export function createInjector() {
}
function createElementInjector(parent = null) {
var host = new SpyElementInjector(null);
var elementInjector = new SpyElementInjector(parent);
return SpyObject.stub(elementInjector,
{
'isExportingComponent': false,
'isExportingElement': false,
'getEventEmitterAccessors': [],
'getHostActionAccessors': [],
'getComponent': new Object(),
'getHost': host
},
{});
var host = new SpyElementInjector();
var elementInjector = new SpyElementInjector();
var res = SpyObject.stub(elementInjector,
{
'isExportingComponent': false,
'isExportingElement': false,
'getEventEmitterAccessors': [],
'getHostActionAccessors': [],
'getComponent': new Object(),
'getHost': host
},
{});
res.prop('parent', parent);
return res;
}
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));
return <any>pei;
}
@ -353,32 +362,3 @@ export function createEmbeddedPv(binders: ElementBinder[] = null) {
@Component({selector: '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 {
describe,
ddescribe,
it,
iit,
expect,
beforeEach,
SpyDependencyProvider
} from 'angular2/test_lib';
import {describe, ddescribe, it, iit, expect, beforeEach} from 'angular2/test_lib';
import {SpyDependencyProvider} from '../spies';
import {
Injector,
ProtoInjector,

View File

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

View File

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

View File

@ -1,5 +1,5 @@
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 {DOM} from 'angular2/src/core/dom/dom_adapter';
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 {ListWrapper, List, MapWrapper} from 'angular2/src/core/facade/collection';
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 {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 {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import {PropertyBindingParser} from 'angular2/src/core/render/dom/compiler/property_binding_parser';
import {CompilePipeline} from 'angular2/src/core/render/dom/compiler/compile_pipeline';
import {MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';

View File

@ -7,16 +7,14 @@ import {
iit,
xit,
expect,
SpyObject,
proxy
SpyObject
} from 'angular2/test_lib';
import {SpyElementRef, SpyDomAdapter} from '../spies';
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 {createRectangle} from './rectangle_mock';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
function assertDimensions(rect: Rectangle, left, right, top, bottom, width, height) {
expect(rect.left).toEqual(left);
@ -33,7 +31,6 @@ export function main() {
it('should allow measuring ElementRefs', inject([AsyncTestCompleter], (async) => {
var ruler = new Ruler(SpyObject.stub(
new SpyDomAdapter(), {'getBoundingClientRect': createRectangle(10, 20, 200, 100)}));
var elRef = <any>new SpyElementRef();
ruler.measure(elRef).then((rect) => {
assertDimensions(rect, 10, 210, 20, 120, 200, 100);
@ -46,7 +43,7 @@ export function main() {
inject([AsyncTestCompleter], (async) => {
var ruler = new Ruler(DOM);
var elRef = <any>new SpyElementRef();
elRef.nativeElement = DOM.createElement('div');
elRef.prop("nativeElement", DOM.createElement('div'));
ruler.measure(elRef).then((rect) => {
// here we are using an element created in a doc fragment so all the measures will come
// back as 0
@ -56,19 +53,4 @@ 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,
afterEach,
AsyncTestCompleter,
SpyChangeDetectorRef,
inject,
SpyObject
} 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 {AsyncPipe} from 'angular2/pipes';
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
} 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';

View File

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

View File

@ -8,16 +8,15 @@ import {
expect,
inject,
beforeEach,
beforeEachBindings,
SpyObject
beforeEachBindings
} 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 {ListWrapper} from 'angular2/src/core/facade/collection';
import {Router, RootRouter} from 'angular2/src/router/router';
import {Pipeline} from 'angular2/src/router/pipeline';
import {RouterOutlet} from 'angular2/src/router/router_outlet';
import {SpyLocation} from 'angular2/src/mock/location_mock';
import {Location} from 'angular2/src/router/location';
import {stringifyInstruction} from 'angular2/src/router/instruction';
@ -203,12 +202,6 @@ function loader(): Promise<Type> {
return PromiseWrapper.resolve(DummyComponent);
}
@proxy
@IMPLEMENTS(RouterOutlet)
class DummyOutlet extends SpyObject {
noSuchMethod(m) { return super.noSuchMethod(m) }
}
class DummyComponent {}
@RouteConfig([new Route({path: '/second', component: DummyComponent, as: 'secondCmp'})])
@ -216,7 +209,7 @@ class DummyParentComp {
}
function makeDummyOutlet() {
var ref = new DummyOutlet();
var ref = new SpyRouterOutlet();
ref.spy('canActivate').andCallFake((_) => PromiseWrapper.resolve(true));
ref.spy('canReuse').andCallFake((_) => PromiseWrapper.resolve(false));
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 {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 {
prop;
@ -22,8 +22,6 @@ class TestObj {
someComplexFunc(a) { return a; }
}
@proxy
@IMPLEMENTS(TestObj)
class SpyTestObj extends SpyObject {
constructor() { super(TestObj); }
noSuchMethod(m) { return super.noSuchMethod(m) }
@ -89,11 +87,6 @@ export function main() {
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",
() => { expect(spyObj.spy("someFunc")).not.toHaveBeenCalled(); });

View File

@ -10,7 +10,6 @@ import {
SpyObject,
proxy
} from 'angular2/test_lib';
import {IMPLEMENTS} from 'angular2/src/core/facade/lang';
import {Serializer} from 'angular2/src/web_workers/shared/serializer';
import {NgZone} from 'angular2/src/core/zone/ng_zone';
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,
beforeEach,
createTestInjector,
beforeEachBindings,
SpyObject,
proxy
beforeEachBindings
} 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 {
ClientMessageBroker,
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 {
constructor(private _messageBroker: ClientMessageBroker) { super(null, null); }
createMessageBroker(channel: string) { return this._messageBroker; }

View File

@ -1,5 +1,4 @@
// Test library and utilities for internal use.
export * from './test';
export * from './src/test_lib/spies';
export * from './src/test_lib/utils';
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 {
isPresent,