2016-04-12 12:40:37 -04:00
|
|
|
import {
|
|
|
|
beforeEach,
|
|
|
|
xdescribe,
|
|
|
|
ddescribe,
|
|
|
|
describe,
|
|
|
|
expect,
|
|
|
|
iit,
|
|
|
|
inject,
|
|
|
|
it,
|
2016-04-28 20:50:03 -04:00
|
|
|
} from '@angular/core/testing/testing_internal';
|
2015-05-27 11:08:14 -04:00
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {hasLifecycleHook} from '@angular/compiler/src/directive_lifecycle_reflector';
|
|
|
|
import {LifecycleHooks} from '@angular/core/src/metadata/lifecycle_hooks';
|
2015-05-27 11:08:14 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('Create DirectiveMetadata', () => {
|
|
|
|
describe('lifecycle', () => {
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("ngOnChanges", () => {
|
|
|
|
it("should be true when the directive has the ngOnChanges method", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnChanges, DirectiveWithOnChangesMethod))
|
2015-08-14 13:03:45 -04:00
|
|
|
.toBe(true);
|
2015-05-27 11:08:14 -04:00
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should be false otherwise", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnChanges, DirectiveNoHooks)).toBe(false);
|
2015-08-14 13:03:45 -04:00
|
|
|
});
|
2015-05-27 11:08:14 -04:00
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("ngOnDestroy", () => {
|
|
|
|
it("should be true when the directive has the ngOnDestroy method", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnDestroy, DirectiveWithOnDestroyMethod))
|
2015-05-27 11:08:14 -04:00
|
|
|
.toBe(true);
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should be false otherwise", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnDestroy, DirectiveNoHooks)).toBe(false);
|
2015-05-27 11:08:14 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("ngOnInit", () => {
|
|
|
|
it("should be true when the directive has the ngOnInit method", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnInit, DirectiveWithOnInitMethod)).toBe(true);
|
2015-05-27 13:14:37 -04:00
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should be false otherwise", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnInit, DirectiveNoHooks)).toBe(false);
|
2015-08-14 13:03:45 -04:00
|
|
|
});
|
2015-05-27 13:14:37 -04:00
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("ngDoCheck", () => {
|
|
|
|
it("should be true when the directive has the ngDoCheck method", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.DoCheck, DirectiveWithOnCheckMethod)).toBe(true);
|
2015-05-27 13:14:37 -04:00
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should be false otherwise", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.DoCheck, DirectiveNoHooks)).toBe(false);
|
2015-08-14 13:03:45 -04:00
|
|
|
});
|
2015-05-27 13:14:37 -04:00
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("ngAfterContentInit", () => {
|
|
|
|
it("should be true when the directive has the ngAfterContentInit method", () => {
|
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterContentInit,
|
|
|
|
DirectiveWithAfterContentInitMethod))
|
2015-08-28 21:11:04 -04:00
|
|
|
.toBe(true);
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should be false otherwise", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterContentInit, DirectiveNoHooks)).toBe(false);
|
2015-08-28 21:11:04 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("ngAfterContentChecked", () => {
|
|
|
|
it("should be true when the directive has the ngAfterContentChecked method", () => {
|
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterContentChecked,
|
|
|
|
DirectiveWithAfterContentCheckedMethod))
|
2015-05-27 11:08:14 -04:00
|
|
|
.toBe(true);
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should be false otherwise", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterContentChecked, DirectiveNoHooks))
|
2015-08-14 13:03:45 -04:00
|
|
|
.toBe(false);
|
2015-05-27 11:08:14 -04:00
|
|
|
});
|
|
|
|
});
|
2015-08-28 21:11:04 -04:00
|
|
|
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("ngAfterViewInit", () => {
|
|
|
|
it("should be true when the directive has the ngAfterViewInit method", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit, DirectiveWithAfterViewInitMethod))
|
2015-08-28 21:11:04 -04:00
|
|
|
.toBe(true);
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should be false otherwise", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit, DirectiveNoHooks)).toBe(false);
|
2015-08-28 21:11:04 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
describe("ngAfterViewChecked", () => {
|
|
|
|
it("should be true when the directive has the ngAfterViewChecked method", () => {
|
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterViewChecked,
|
|
|
|
DirectiveWithAfterViewCheckedMethod))
|
2015-08-28 21:11:04 -04:00
|
|
|
.toBe(true);
|
|
|
|
});
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
it("should be false otherwise", () => {
|
2015-10-01 23:47:49 -04:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterViewChecked, DirectiveNoHooks)).toBe(false);
|
2015-08-28 21:11:04 -04:00
|
|
|
});
|
|
|
|
});
|
2015-05-27 11:08:14 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
class DirectiveNoHooks {}
|
|
|
|
|
2015-08-28 00:19:56 -04:00
|
|
|
class DirectiveWithOnChangesMethod {
|
2016-06-08 18:45:15 -04:00
|
|
|
ngOnChanges(_: any /** TODO #9100 */) {}
|
2015-05-27 11:08:14 -04:00
|
|
|
}
|
|
|
|
|
2015-05-27 13:14:37 -04:00
|
|
|
class DirectiveWithOnInitMethod {
|
refactor(lifecycle): prefix lifecycle methods with "ng"
BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.
To fix, just rename these methods:
* onInit
* onDestroy
* doCheck
* onChanges
* afterContentInit
* afterContentChecked
* afterViewInit
* afterViewChecked
* _Router Hooks_
* onActivate
* onReuse
* onDeactivate
* canReuse
* canDeactivate
To:
* ngOnInit,
* ngOnDestroy,
* ngDoCheck,
* ngOnChanges,
* ngAfterContentInit,
* ngAfterContentChecked,
* ngAfterViewInit,
* ngAfterViewChecked
* _Router Hooks_
* routerOnActivate
* routerOnReuse
* routerOnDeactivate
* routerCanReuse
* routerCanDeactivate
The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.
Closes #5036
2015-11-16 20:04:36 -05:00
|
|
|
ngOnInit() {}
|
2015-05-27 13:14:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class DirectiveWithOnCheckMethod {
|
refactor(lifecycle): prefix lifecycle methods with "ng"
BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.
To fix, just rename these methods:
* onInit
* onDestroy
* doCheck
* onChanges
* afterContentInit
* afterContentChecked
* afterViewInit
* afterViewChecked
* _Router Hooks_
* onActivate
* onReuse
* onDeactivate
* canReuse
* canDeactivate
To:
* ngOnInit,
* ngOnDestroy,
* ngDoCheck,
* ngOnChanges,
* ngAfterContentInit,
* ngAfterContentChecked,
* ngAfterViewInit,
* ngAfterViewChecked
* _Router Hooks_
* routerOnActivate
* routerOnReuse
* routerOnDeactivate
* routerCanReuse
* routerCanDeactivate
The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.
Closes #5036
2015-11-16 20:04:36 -05:00
|
|
|
ngDoCheck() {}
|
2015-05-27 13:14:37 -04:00
|
|
|
}
|
|
|
|
|
2015-05-27 11:08:14 -04:00
|
|
|
class DirectiveWithOnDestroyMethod {
|
refactor(lifecycle): prefix lifecycle methods with "ng"
BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.
To fix, just rename these methods:
* onInit
* onDestroy
* doCheck
* onChanges
* afterContentInit
* afterContentChecked
* afterViewInit
* afterViewChecked
* _Router Hooks_
* onActivate
* onReuse
* onDeactivate
* canReuse
* canDeactivate
To:
* ngOnInit,
* ngOnDestroy,
* ngDoCheck,
* ngOnChanges,
* ngAfterContentInit,
* ngAfterContentChecked,
* ngAfterViewInit,
* ngAfterViewChecked
* _Router Hooks_
* routerOnActivate
* routerOnReuse
* routerOnDeactivate
* routerCanReuse
* routerCanDeactivate
The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.
Closes #5036
2015-11-16 20:04:36 -05:00
|
|
|
ngOnDestroy() {}
|
2015-05-27 11:08:14 -04:00
|
|
|
}
|
|
|
|
|
2015-08-28 21:11:04 -04:00
|
|
|
class DirectiveWithAfterContentInitMethod {
|
refactor(lifecycle): prefix lifecycle methods with "ng"
BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.
To fix, just rename these methods:
* onInit
* onDestroy
* doCheck
* onChanges
* afterContentInit
* afterContentChecked
* afterViewInit
* afterViewChecked
* _Router Hooks_
* onActivate
* onReuse
* onDeactivate
* canReuse
* canDeactivate
To:
* ngOnInit,
* ngOnDestroy,
* ngDoCheck,
* ngOnChanges,
* ngAfterContentInit,
* ngAfterContentChecked,
* ngAfterViewInit,
* ngAfterViewChecked
* _Router Hooks_
* routerOnActivate
* routerOnReuse
* routerOnDeactivate
* routerCanReuse
* routerCanDeactivate
The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.
Closes #5036
2015-11-16 20:04:36 -05:00
|
|
|
ngAfterContentInit() {}
|
2015-08-28 21:11:04 -04:00
|
|
|
}
|
|
|
|
|
2015-08-28 00:19:56 -04:00
|
|
|
class DirectiveWithAfterContentCheckedMethod {
|
refactor(lifecycle): prefix lifecycle methods with "ng"
BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.
To fix, just rename these methods:
* onInit
* onDestroy
* doCheck
* onChanges
* afterContentInit
* afterContentChecked
* afterViewInit
* afterViewChecked
* _Router Hooks_
* onActivate
* onReuse
* onDeactivate
* canReuse
* canDeactivate
To:
* ngOnInit,
* ngOnDestroy,
* ngDoCheck,
* ngOnChanges,
* ngAfterContentInit,
* ngAfterContentChecked,
* ngAfterViewInit,
* ngAfterViewChecked
* _Router Hooks_
* routerOnActivate
* routerOnReuse
* routerOnDeactivate
* routerCanReuse
* routerCanDeactivate
The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.
Closes #5036
2015-11-16 20:04:36 -05:00
|
|
|
ngAfterContentChecked() {}
|
2015-07-04 09:04:50 -04:00
|
|
|
}
|
2015-08-28 21:11:04 -04:00
|
|
|
|
|
|
|
class DirectiveWithAfterViewInitMethod {
|
refactor(lifecycle): prefix lifecycle methods with "ng"
BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.
To fix, just rename these methods:
* onInit
* onDestroy
* doCheck
* onChanges
* afterContentInit
* afterContentChecked
* afterViewInit
* afterViewChecked
* _Router Hooks_
* onActivate
* onReuse
* onDeactivate
* canReuse
* canDeactivate
To:
* ngOnInit,
* ngOnDestroy,
* ngDoCheck,
* ngOnChanges,
* ngAfterContentInit,
* ngAfterContentChecked,
* ngAfterViewInit,
* ngAfterViewChecked
* _Router Hooks_
* routerOnActivate
* routerOnReuse
* routerOnDeactivate
* routerCanReuse
* routerCanDeactivate
The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.
Closes #5036
2015-11-16 20:04:36 -05:00
|
|
|
ngAfterViewInit() {}
|
2015-08-28 21:11:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class DirectiveWithAfterViewCheckedMethod {
|
refactor(lifecycle): prefix lifecycle methods with "ng"
BREAKING CHANGE:
Previously, components that would implement lifecycle interfaces would include methods
like "onChanges" or "afterViewInit." Given that components were at risk of using such
names without realizing that Angular would call the methods at different points of
the component lifecycle. This change adds an "ng" prefix to all lifecycle hook methods,
far reducing the risk of an accidental name collision.
To fix, just rename these methods:
* onInit
* onDestroy
* doCheck
* onChanges
* afterContentInit
* afterContentChecked
* afterViewInit
* afterViewChecked
* _Router Hooks_
* onActivate
* onReuse
* onDeactivate
* canReuse
* canDeactivate
To:
* ngOnInit,
* ngOnDestroy,
* ngDoCheck,
* ngOnChanges,
* ngAfterContentInit,
* ngAfterContentChecked,
* ngAfterViewInit,
* ngAfterViewChecked
* _Router Hooks_
* routerOnActivate
* routerOnReuse
* routerOnDeactivate
* routerCanReuse
* routerCanDeactivate
The names of lifecycle interfaces and enums have not changed, though interfaces
have been updated to reflect the new method names.
Closes #5036
2015-11-16 20:04:36 -05:00
|
|
|
ngAfterViewChecked() {}
|
2015-08-28 21:11:04 -04:00
|
|
|
}
|