refactor(core): Move LifeCycle functionality into ApplicationRef.
BREAKING CHANGE: Before: constructor(@Inject(LifeCycle) lifecycle) { lifecycle.tick(); } After: constructor(@Inject(ApplicationRef) appRef) { appRef.tick(); } Closes #5008
This commit is contained in:
30
modules/angular2/test/core/application_ref_spec.ts
Normal file
30
modules/angular2/test/core/application_ref_spec.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import {
|
||||
ddescribe,
|
||||
describe,
|
||||
it,
|
||||
iit,
|
||||
xit,
|
||||
expect,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
el,
|
||||
AsyncTestCompleter,
|
||||
fakeAsync,
|
||||
tick,
|
||||
inject
|
||||
} from 'angular2/testing_internal';
|
||||
import {SpyChangeDetector} from './spies';
|
||||
import {ApplicationRef_} from "angular2/src/core/application_ref";
|
||||
import {ChangeDetectorRef_} from "angular2/src/core/change_detection/change_detector_ref";
|
||||
|
||||
export function main() {
|
||||
describe("ApplicationRef", () => {
|
||||
it("should throw when reentering tick", () => {
|
||||
var cd = <any>new SpyChangeDetector();
|
||||
var ref = new ApplicationRef_(null, null, null);
|
||||
ref.registerChangeDetector(new ChangeDetectorRef_(cd));
|
||||
cd.spy("detectChanges").andCallFake(() => ref.tick());
|
||||
expect(() => ref.tick()).toThrowError("ApplicationRef.tick is called recursively");
|
||||
});
|
||||
});
|
||||
}
|
@ -17,7 +17,7 @@ import {Component, Directive, View} from 'angular2/core';
|
||||
import {DOM} from 'angular2/src/core/dom/dom_adapter';
|
||||
import {DOCUMENT} from 'angular2/render';
|
||||
import {PromiseWrapper} from 'angular2/src/core/facade/async';
|
||||
import {provide, Inject, Injector, LifeCycle} from 'angular2/core';
|
||||
import {provide, Inject, Injector} from 'angular2/core';
|
||||
import {ExceptionHandler} from 'angular2/src/core/facade/exceptions';
|
||||
import {Testability, TestabilityRegistry} from 'angular2/src/core/testability/testability';
|
||||
import {IS_DART} from '../platform';
|
||||
@ -54,9 +54,9 @@ class HelloRootCmp3 {
|
||||
@Component({selector: 'hello-app'})
|
||||
@View({template: ''})
|
||||
class HelloRootCmp4 {
|
||||
lc;
|
||||
appRef;
|
||||
|
||||
constructor(@Inject(LifeCycle) lc) { this.lc = lc; }
|
||||
constructor(@Inject(ApplicationRef) appRef) { this.appRef = appRef; }
|
||||
}
|
||||
|
||||
@Component({selector: 'hello-app'})
|
||||
@ -179,7 +179,7 @@ export function main() {
|
||||
var refPromise = bootstrap(HelloRootCmp4, testProviders);
|
||||
|
||||
refPromise.then((ref) => {
|
||||
expect(ref.hostComponent.lc).toBe((<ComponentRef_>ref).injector.get(LifeCycle));
|
||||
expect(ref.hostComponent.appRef).toBe((<ComponentRef_>ref).injector.get(ApplicationRef));
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
@ -1,29 +0,0 @@
|
||||
import {
|
||||
ddescribe,
|
||||
describe,
|
||||
it,
|
||||
iit,
|
||||
xit,
|
||||
expect,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
el,
|
||||
AsyncTestCompleter,
|
||||
fakeAsync,
|
||||
tick,
|
||||
inject
|
||||
} from 'angular2/testing_internal';
|
||||
import {SpyChangeDetector} from '../spies';
|
||||
import {LifeCycle_} from "angular2/src/core/life_cycle/life_cycle";
|
||||
|
||||
export function main() {
|
||||
describe("LifeCycle", () => {
|
||||
it("should throw when reentering tick", () => {
|
||||
var cd = <any>new SpyChangeDetector();
|
||||
var lc = new LifeCycle_(cd, false);
|
||||
|
||||
cd.spy("detectChanges").andCallFake(() => lc.tick());
|
||||
expect(() => lc.tick()).toThrowError("LifeCycle.tick is called recursively");
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user