feat(core): added afterContentInit, afterViewInit, and afterViewChecked hooks

Closes #3897
This commit is contained in:
vsavkin
2015-08-28 18:11:04 -07:00
committed by Victor Savkin
parent f93cd9ced7
commit d49bc438e8
36 changed files with 974 additions and 253 deletions

View File

@ -88,6 +88,25 @@ main() {
});
});
describe("afterContentInit", () {
it("should be true when the directive implements AfterContentInit", () {
expect(
metadata(DirectiveImplementingAfterContentInit, new Directive())
.callAfterContentInit).toBe(true);
});
it("should be true when the lifecycle includes afterContentInit", () {
expect(metadata(DirectiveNoHooks,
new Directive(lifecycle: [LifecycleEvent.AfterContentInit]))
.callAfterContentInit).toBe(true);
});
it("should be false otherwise", () {
expect(metadata(DirectiveNoHooks, new Directive())
.callAfterContentInit).toBe(false);
});
});
describe("afterContentChecked", () {
it("should be true when the directive implements AfterContentChecked", () {
expect(
@ -106,6 +125,44 @@ main() {
.callAfterContentChecked).toBe(false);
});
});
describe("afterViewInit", () {
it("should be true when the directive implements AfterViewInit", () {
expect(
metadata(DirectiveImplementingAfterViewInit, new Directive())
.callAfterViewInit).toBe(true);
});
it("should be true when the lifecycle includes afterViewInit", () {
expect(metadata(DirectiveNoHooks,
new Directive(lifecycle: [LifecycleEvent.AfterViewInit]))
.callAfterViewInit).toBe(true);
});
it("should be false otherwise", () {
expect(metadata(DirectiveNoHooks, new Directive())
.callAfterViewInit).toBe(false);
});
});
describe("afterViewChecked", () {
it("should be true when the directive implements AfterViewChecked", () {
expect(
metadata(DirectiveImplementingAfterViewChecked, new Directive())
.callAfterViewChecked).toBe(true);
});
it("should be true when the lifecycle includes afterViewChecked", () {
expect(metadata(DirectiveNoHooks,
new Directive(lifecycle: [LifecycleEvent.AfterViewChecked]))
.callAfterViewChecked).toBe(true);
});
it("should be false otherwise", () {
expect(metadata(DirectiveNoHooks, new Directive())
.callAfterViewChecked).toBe(false);
});
});
});
});
}
@ -128,6 +185,18 @@ class DirectiveImplementingOnDestroy implements OnDestroy {
onDestroy() {}
}
class DirectiveImplementingAfterContentInit implements AfterContentInit {
afterContentInit() {}
}
class DirectiveImplementingAfterContentChecked implements AfterContentChecked {
afterContentChecked() {}
}
class DirectiveImplementingAfterViewInit implements AfterViewInit {
afterViewInit() {}
}
class DirectiveImplementingAfterViewChecked implements AfterViewChecked {
afterViewChecked() {}
}

View File

@ -102,6 +102,26 @@ export function main() {
});
});
describe("afterContentInit", () => {
it("should be true when the directive has the afterContentInit method", () => {
expect(metadata(DirectiveWithAfterContentInitMethod, new DirectiveMetadata({}))
.callAfterContentInit)
.toBe(true);
});
it("should be true when the lifecycle includes afterContentInit", () => {
expect(metadata(DirectiveNoHooks,
new DirectiveMetadata({lifecycle: [LifecycleEvent.AfterContentInit]}))
.callAfterContentInit)
.toBe(true);
});
it("should be false otherwise", () => {
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callAfterContentInit)
.toBe(false);
});
});
describe("afterContentChecked", () => {
it("should be true when the directive has the afterContentChecked method", () => {
expect(metadata(DirectiveWithAfterContentCheckedMethod, new DirectiveMetadata({}))
@ -121,6 +141,46 @@ export function main() {
.toBe(false);
});
});
describe("afterViewInit", () => {
it("should be true when the directive has the afterViewInit method", () => {
expect(metadata(DirectiveWithAfterViewInitMethod, new DirectiveMetadata({}))
.callAfterViewInit)
.toBe(true);
});
it("should be true when the lifecycle includes afterViewInit", () => {
expect(metadata(DirectiveNoHooks,
new DirectiveMetadata({lifecycle: [LifecycleEvent.AfterViewInit]}))
.callAfterViewInit)
.toBe(true);
});
it("should be false otherwise", () => {
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callAfterViewInit).toBe(false);
});
});
describe("afterViewChecked", () => {
it("should be true when the directive has the afterViewChecked method", () => {
expect(metadata(DirectiveWithAfterViewCheckedMethod, new DirectiveMetadata({}))
.callAfterViewChecked)
.toBe(true);
});
it("should be true when the lifecycle includes afterViewChecked", () => {
expect(metadata(DirectiveNoHooks,
new DirectiveMetadata({lifecycle: [LifecycleEvent.AfterViewChecked]}))
.callAfterViewChecked)
.toBe(true);
});
it("should be false otherwise", () => {
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callAfterViewChecked)
.toBe(false);
});
});
});
});
}
@ -143,6 +203,18 @@ class DirectiveWithOnDestroyMethod {
onDestroy(_) {}
}
class DirectiveWithAfterContentInitMethod {
afterContentInit() {}
}
class DirectiveWithAfterContentCheckedMethod {
afterContentChecked() {}
}
class DirectiveWithAfterViewInitMethod {
afterViewInit() {}
}
class DirectiveWithAfterViewCheckedMethod {
afterViewChecked() {}
}