From 343dcfa0c08771b6cc8cf589124b161236e95aa2 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Wed, 26 Aug 2015 11:41:41 -0700 Subject: [PATCH] refactor(tests): removed @IMPLEMENTS --- modules/angular1_router/lib/facades.es5 | 6 - modules/angular2/src/core/facade/lang.dart | 5 - modules/angular2/src/core/facade/lang.ts | 7 -- .../src/http/backends/mock_backend.ts | 8 +- modules/angular2/src/mock/location_mock.ts | 28 ++--- modules/angular2/src/router/location.ts | 53 ++++----- .../angular2/src/router/path_recognizer.ts | 1 - modules/angular2/src/test_lib/spies.dart | 36 ------ modules/angular2/src/test_lib/spies.ts | 28 ----- modules/angular2/src/test_lib/test_lib.dart | 4 + modules/angular2/src/test_lib/test_lib.ts | 2 + .../change_detection/change_detection_spec.ts | 14 +-- .../differs/iterable_differs_spec.ts | 13 +-- .../test/core/compiler/compiler_spec.ts | 30 +---- .../core/compiler/element_injector_spec.ts | 50 +++------ .../core/compiler/proto_view_factory_spec.ts | 18 +-- .../core/compiler/view_container_ref_spec.ts | 34 ++---- .../test/core/compiler/view_manager_spec.ts | 30 +---- .../core/compiler/view_manager_utils_spec.ts | 76 +++++-------- .../angular2/test/core/di/injector_spec.ts | 11 +- .../directives/observable_list_diff_spec.dart | 6 + .../test/core/life_cycle/life_cycle_spec.ts | 5 +- .../dom/compiler/directive_parser_spec.ts | 2 +- .../core/render/dom/compiler/pipeline_spec.ts | 2 +- .../compiler/property_binding_parser_spec.ts | 1 - .../angular2/test/core/services/ruler_spec.ts | 26 +---- modules/angular2/test/core/spies.dart | 105 ++++++++++++++++++ modules/angular2/test/core/spies.ts | 90 +++++++++++++++ .../angular2/test/pipes/async_pipe_spec.ts | 4 +- modules/angular2/test/pipes/spies.dart | 9 ++ modules/angular2/test/pipes/spies.ts | 7 ++ .../router/integration/router_link_spec.ts | 2 +- .../angular2/test/router/router_link_spec.ts | 22 +--- modules/angular2/test/router/router_spec.ts | 15 +-- modules/angular2/test/router/spies.dart | 19 ++++ modules/angular2/test/router/spies.ts | 14 +++ .../angular2/test/test_lib/test_lib_spec.ts | 9 +- .../worker/event_dispatcher_spec.ts | 1 - .../test/web_workers/worker/spies.dart | 11 ++ .../angular2/test/web_workers/worker/spies.ts | 7 ++ .../test/web_workers/worker/xhr_impl_spec.ts | 14 +-- modules/angular2/test_lib.ts | 1 - modules/examples/src/material/demo_common.ts | 2 +- 43 files changed, 402 insertions(+), 426 deletions(-) delete mode 100644 modules/angular2/src/test_lib/spies.dart delete mode 100644 modules/angular2/src/test_lib/spies.ts create mode 100644 modules/angular2/test/core/spies.dart create mode 100644 modules/angular2/test/core/spies.ts create mode 100644 modules/angular2/test/pipes/spies.dart create mode 100644 modules/angular2/test/pipes/spies.ts create mode 100644 modules/angular2/test/router/spies.dart create mode 100644 modules/angular2/test/router/spies.ts create mode 100644 modules/angular2/test/web_workers/worker/spies.dart create mode 100644 modules/angular2/test/web_workers/worker/spies.ts diff --git a/modules/angular1_router/lib/facades.es5 b/modules/angular1_router/lib/facades.es5 index e0d6024e6f..d65f3667e3 100644 --- a/modules/angular1_router/lib/facades.es5 +++ b/modules/angular1_router/lib/facades.es5 @@ -4,12 +4,6 @@ function CONST() { }); } -function IMPLEMENTS(_) { - return (function(t) { - return t; - }); -} - function CONST_EXPR(expr) { return expr; } diff --git a/modules/angular2/src/core/facade/lang.dart b/modules/angular2/src/core/facade/lang.dart index fa071bcda0..7c0a40c323 100644 --- a/modules/angular2/src/core/facade/lang.dart +++ b/modules/angular2/src/core/facade/lang.dart @@ -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; diff --git a/modules/angular2/src/core/facade/lang.ts b/modules/angular2/src/core/facade/lang.ts index f624846311..222eb39bbe 100644 --- a/modules/angular2/src/core/facade/lang.ts +++ b/modules/angular2/src/core/facade/lang.ts @@ -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; } diff --git a/modules/angular2/src/http/backends/mock_backend.ts b/modules/angular2/src/http/backends/mock_backend.ts index 9ed9030964..bd9f8432be 100644 --- a/modules/angular2/src/http/backends/mock_backend.ts +++ b/modules/angular2/src/http/backends/mock_backend.ts @@ -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 diff --git a/modules/angular2/src/mock/location_mock.ts b/modules/angular2/src/mock/location_mock.ts index e85d377b64..0d38a928ec 100644 --- a/modules/angular2/src/mock/location_mock.ts +++ b/modules/angular2/src/mock/location_mock.ts @@ -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; - _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 = []; + _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; } } diff --git a/modules/angular2/src/router/location.ts b/modules/angular2/src/router/location.ts index cd383bf5ef..bdb40e2cec 100644 --- a/modules/angular2/src/router/location.ts +++ b/modules/angular2/src/router/location.ts @@ -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)) { diff --git a/modules/angular2/src/router/path_recognizer.ts b/modules/angular2/src/router/path_recognizer.ts index 2e3550ab27..63592d9526 100644 --- a/modules/angular2/src/router/path_recognizer.ts +++ b/modules/angular2/src/router/path_recognizer.ts @@ -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'; diff --git a/modules/angular2/src/test_lib/spies.dart b/modules/angular2/src/test_lib/spies.dart deleted file mode 100644 index 9769c93ef8..0000000000 --- a/modules/angular2/src/test_lib/spies.dart +++ /dev/null @@ -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); -} diff --git a/modules/angular2/src/test_lib/spies.ts b/modules/angular2/src/test_lib/spies.ts deleted file mode 100644 index c1606b5109..0000000000 --- a/modules/angular2/src/test_lib/spies.ts +++ /dev/null @@ -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); } -} diff --git a/modules/angular2/src/test_lib/test_lib.dart b/modules/angular2/src/test_lib/test_lib.dart index e48becf8ee..0c94cbe234 100644 --- a/modules/angular2/src/test_lib/test_lib.dart +++ b/modules/angular2/src/test_lib/test_lib.dart @@ -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; diff --git a/modules/angular2/src/test_lib/test_lib.ts b/modules/angular2/src/test_lib/test_lib.ts index 0bdde39112..7119b08e58 100644 --- a/modules/angular2/src/test_lib/test_lib.ts +++ b/modules/angular2/src/test_lib/test_lib.ts @@ -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; diff --git a/modules/angular2/test/core/change_detection/change_detection_spec.ts b/modules/angular2/test/core/change_detection/change_detection_spec.ts index f1b76db558..8a520c546f 100644 --- a/modules/angular2/test/core/change_detection/change_detection_spec.ts +++ b/modules/angular2/test/core/change_detection/change_detection_spec.ts @@ -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, diff --git a/modules/angular2/test/core/change_detection/differs/iterable_differs_spec.ts b/modules/angular2/test/core/change_detection/differs/iterable_differs_spec.ts index 7225f5dbb7..de0dba23bf 100644 --- a/modules/angular2/test/core/change_detection/differs/iterable_differs_spec.ts +++ b/modules/angular2/test/core/change_detection/differs/iterable_differs_spec.ts @@ -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'; diff --git a/modules/angular2/test/core/compiler/compiler_spec.ts b/modules/angular2/test/core/compiler/compiler_spec.ts index 5d7364d2b4..c676bffcb1 100644 --- a/modules/angular2/test/core/compiler/compiler_spec.ts +++ b/modules/angular2/test/core/compiler/compiler_spec.ts @@ -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 = new Map(); diff --git a/modules/angular2/test/core/compiler/element_injector_spec.ts b/modules/angular2/test/core/compiler/element_injector_spec.ts index a4b5e5747a..c980a52b59 100644 --- a/modules/angular2/test/core/compiler/element_injector_spec.ts +++ b/modules/angular2/test/core/compiler/element_injector_spec.ts @@ -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 { } export function main() { - var defaultPreBuiltObjects = new PreBuiltObjects(null, new DummyView(), new DummyElementRef(), null); + var defaultPreBuiltObjects = new PreBuiltObjects(null, createDummyView(), 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(new DummyElementRef()); + var templateRef = new TemplateRef(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 = new DummyView(); - var childView = new DummyView(); - childView.changeDetector = cd; + var view = 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, new DummyElementRef(), null)); + new PreBuiltObjects(null, view, 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 = new DummyView(); - view.changeDetector =cd; + var view = createDummyView(cd); var binding = DirectiveBinding.createFromType(DirectiveNeedsChangeDetectorRef, new DirectiveMetadata()); var inj = injector(ListWrapper.concat([binding], extraBindings), null, false, - new PreBuiltObjects(null, view, new DummyElementRef(), null)); + new PreBuiltObjects(null, view, 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(new DummyElementRef()); + var templateRef = new TemplateRef(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(new DummyElementRef())); + var preBuiltObjects = new PreBuiltObjects(null, null, null, new TemplateRef(new SpyElementRef())); var inj = injector(ListWrapper.concat([ NeedsTemplateRefQuery ], extraBindings), null, diff --git a/modules/angular2/test/core/compiler/proto_view_factory_spec.ts b/modules/angular2/test/core/compiler/proto_view_factory_spec.ts index 6b306f4fbb..149b183e46 100644 --- a/modules/angular2/test/core/compiler/proto_view_factory_spec.ts +++ b/modules/angular2/test/core/compiler/proto_view_factory_spec.ts @@ -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 { } diff --git a/modules/angular2/test/core/compiler/view_container_ref_spec.ts b/modules/angular2/test/core/compiler/view_container_ref_spec.ts index b2b46e48ce..47a25c7175 100644 --- a/modules/angular2/test/core/compiler/view_container_ref_spec.ts +++ b/modules/angular2/test/core/compiler/view_container_ref_spec.ts @@ -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 = [new AppViewSpy()]; + view.prop("viewContainers", [appVc]); + appVc.views = [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) } -} +} \ No newline at end of file diff --git a/modules/angular2/test/core/compiler/view_manager_spec.ts b/modules/angular2/test/core/compiler/view_manager_spec.ts index 344188e274..670a95cd81 100644 --- a/modules/angular2/test/core/compiler/view_manager_spec.ts +++ b/modules/angular2/test/core/compiler/view_manager_spec.ts @@ -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) } -} diff --git a/modules/angular2/test/core/compiler/view_manager_utils_spec.ts b/modules/angular2/test/core/compiler/view_manager_utils_spec.ts index 4ad052ddfa..5dea03f3be 100644 --- a/modules/angular2/test/core/compiler/view_manager_utils_spec.ts +++ b/modules/angular2/test/core/compiler/view_manager_utils_spec.ts @@ -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 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) } -} diff --git a/modules/angular2/test/core/di/injector_spec.ts b/modules/angular2/test/core/di/injector_spec.ts index e4f5ed6336..768b2dc086 100644 --- a/modules/angular2/test/core/di/injector_spec.ts +++ b/modules/angular2/test/core/di/injector_spec.ts @@ -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, diff --git a/modules/angular2/test/core/directives/observable_list_diff_spec.dart b/modules/angular2/test/core/directives/observable_list_diff_spec.dart index 441c851e17..ccb2ebb616 100644 --- a/modules/angular2/test/core/directives/observable_list_diff_spec.dart +++ b/modules/angular2/test/core/directives/observable_list_diff_spec.dart @@ -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; diff --git a/modules/angular2/test/core/life_cycle/life_cycle_spec.ts b/modules/angular2/test/core/life_cycle/life_cycle_spec.ts index a83944b51e..1df9710f3a 100644 --- a/modules/angular2/test/core/life_cycle/life_cycle_spec.ts +++ b/modules/angular2/test/core/life_cycle/life_cycle_spec.ts @@ -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", () => { diff --git a/modules/angular2/test/core/render/dom/compiler/directive_parser_spec.ts b/modules/angular2/test/core/render/dom/compiler/directive_parser_spec.ts index cbd0ec316a..6c6af6b778 100644 --- a/modules/angular2/test/core/render/dom/compiler/directive_parser_spec.ts +++ b/modules/angular2/test/core/render/dom/compiler/directive_parser_spec.ts @@ -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'; diff --git a/modules/angular2/test/core/render/dom/compiler/pipeline_spec.ts b/modules/angular2/test/core/render/dom/compiler/pipeline_spec.ts index 1d9367cd84..9121499b9f 100644 --- a/modules/angular2/test/core/render/dom/compiler/pipeline_spec.ts +++ b/modules/angular2/test/core/render/dom/compiler/pipeline_spec.ts @@ -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'; diff --git a/modules/angular2/test/core/render/dom/compiler/property_binding_parser_spec.ts b/modules/angular2/test/core/render/dom/compiler/property_binding_parser_spec.ts index a4d0f63357..ad8e70d212 100644 --- a/modules/angular2/test/core/render/dom/compiler/property_binding_parser_spec.ts +++ b/modules/angular2/test/core/render/dom/compiler/property_binding_parser_spec.ts @@ -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'; diff --git a/modules/angular2/test/core/services/ruler_spec.ts b/modules/angular2/test/core/services/ruler_spec.ts index e5a55cf7f1..f65aefa019 100644 --- a/modules/angular2/test/core/services/ruler_spec.ts +++ b/modules/angular2/test/core/services/ruler_spec.ts @@ -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 = 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 = 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) } -} +} \ No newline at end of file diff --git a/modules/angular2/test/core/spies.dart b/modules/angular2/test/core/spies.dart new file mode 100644 index 0000000000..a85dd3bd19 --- /dev/null +++ b/modules/angular2/test/core/spies.dart @@ -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); +} diff --git a/modules/angular2/test/core/spies.ts b/modules/angular2/test/core/spies.ts new file mode 100644 index 0000000000..8de1208889 --- /dev/null +++ b/modules/angular2/test/core/spies.ts @@ -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); } +} \ No newline at end of file diff --git a/modules/angular2/test/pipes/async_pipe_spec.ts b/modules/angular2/test/pipes/async_pipe_spec.ts index 572772698d..cfb4852c79 100644 --- a/modules/angular2/test/pipes/async_pipe_spec.ts +++ b/modules/angular2/test/pipes/async_pipe_spec.ts @@ -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 { diff --git a/modules/angular2/test/pipes/spies.dart b/modules/angular2/test/pipes/spies.dart new file mode 100644 index 0000000000..cc5b80ac01 --- /dev/null +++ b/modules/angular2/test/pipes/spies.dart @@ -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); +} diff --git a/modules/angular2/test/pipes/spies.ts b/modules/angular2/test/pipes/spies.ts new file mode 100644 index 0000000000..5aac0afcae --- /dev/null +++ b/modules/angular2/test/pipes/spies.ts @@ -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); } +} \ No newline at end of file diff --git a/modules/angular2/test/router/integration/router_link_spec.ts b/modules/angular2/test/router/integration/router_link_spec.ts index f5a2393789..e16200cf83 100644 --- a/modules/angular2/test/router/integration/router_link_spec.ts +++ b/modules/angular2/test/router/integration/router_link_spec.ts @@ -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'; diff --git a/modules/angular2/test/router/router_link_spec.ts b/modules/angular2/test/router/router_link_spec.ts index f551f071d9..dc5d6fc487 100644 --- a/modules/angular2/test/router/router_link_spec.ts +++ b/modules/angular2/test/router/router_link_spec.ts @@ -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; diff --git a/modules/angular2/test/router/router_spec.ts b/modules/angular2/test/router/router_spec.ts index 2171b5d66c..b06451cf84 100644 --- a/modules/angular2/test/router/router_spec.ts +++ b/modules/angular2/test/router/router_spec.ts @@ -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 { 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)); diff --git a/modules/angular2/test/router/spies.dart b/modules/angular2/test/router/spies.dart new file mode 100644 index 0000000000..51cb0cd3d1 --- /dev/null +++ b/modules/angular2/test/router/spies.dart @@ -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); +} diff --git a/modules/angular2/test/router/spies.ts b/modules/angular2/test/router/spies.ts new file mode 100644 index 0000000000..4fab451ba1 --- /dev/null +++ b/modules/angular2/test/router/spies.ts @@ -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); } +} \ No newline at end of file diff --git a/modules/angular2/test/test_lib/test_lib_spec.ts b/modules/angular2/test/test_lib/test_lib_spec.ts index 7c16b7a42b..34cc99bb4b 100644 --- a/modules/angular2/test/test_lib/test_lib_spec.ts +++ b/modules/angular2/test/test_lib/test_lib_spec.ts @@ -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 = 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(); }); diff --git a/modules/angular2/test/web_workers/worker/event_dispatcher_spec.ts b/modules/angular2/test/web_workers/worker/event_dispatcher_spec.ts index 729efb04fa..8a1686884b 100644 --- a/modules/angular2/test/web_workers/worker/event_dispatcher_spec.ts +++ b/modules/angular2/test/web_workers/worker/event_dispatcher_spec.ts @@ -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'; diff --git a/modules/angular2/test/web_workers/worker/spies.dart b/modules/angular2/test/web_workers/worker/spies.dart new file mode 100644 index 0000000000..91a311d829 --- /dev/null +++ b/modules/angular2/test/web_workers/worker/spies.dart @@ -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); +} + + diff --git a/modules/angular2/test/web_workers/worker/spies.ts b/modules/angular2/test/web_workers/worker/spies.ts new file mode 100644 index 0000000000..de582d95d6 --- /dev/null +++ b/modules/angular2/test/web_workers/worker/spies.ts @@ -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); } +} diff --git a/modules/angular2/test/web_workers/worker/xhr_impl_spec.ts b/modules/angular2/test/web_workers/worker/xhr_impl_spec.ts index 0c3e68444d..e5e2464698 100644 --- a/modules/angular2/test/web_workers/worker/xhr_impl_spec.ts +++ b/modules/angular2/test/web_workers/worker/xhr_impl_spec.ts @@ -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; } diff --git a/modules/angular2/test_lib.ts b/modules/angular2/test_lib.ts index f7a43aaf98..081e0fe211 100644 --- a/modules/angular2/test_lib.ts +++ b/modules/angular2/test_lib.ts @@ -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'; diff --git a/modules/examples/src/material/demo_common.ts b/modules/examples/src/material/demo_common.ts index cbe2774d6b..1a4a5a09a2 100644 --- a/modules/examples/src/material/demo_common.ts +++ b/modules/examples/src/material/demo_common.ts @@ -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,