2016-06-08 16:38:52 -07:00
|
|
|
import {beforeEach, xdescribe, ddescribe, describe, expect, iit, inject, it,} from '@angular/core/testing/testing_internal';
|
2015-05-27 08:08:14 -07:00
|
|
|
|
2016-04-28 17:50:03 -07:00
|
|
|
import {hasLifecycleHook} from '@angular/compiler/src/directive_lifecycle_reflector';
|
|
|
|
|
import {LifecycleHooks} from '@angular/core/src/metadata/lifecycle_hooks';
|
2015-05-27 08:08:14 -07:00
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
|
describe('Create DirectiveMetadata', () => {
|
|
|
|
|
describe('lifecycle', () => {
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
describe('ngOnChanges', () => {
|
|
|
|
|
it('should be true when the directive has the ngOnChanges method', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnChanges, DirectiveWithOnChangesMethod))
|
2015-08-14 10:03:45 -07:00
|
|
|
.toBe(true);
|
2015-05-27 08:08:14 -07:00
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
it('should be false otherwise', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnChanges, DirectiveNoHooks)).toBe(false);
|
2015-08-14 10:03:45 -07:00
|
|
|
});
|
2015-05-27 08:08:14 -07:00
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
describe('ngOnDestroy', () => {
|
|
|
|
|
it('should be true when the directive has the ngOnDestroy method', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnDestroy, DirectiveWithOnDestroyMethod))
|
2015-05-27 08:08:14 -07:00
|
|
|
.toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
it('should be false otherwise', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnDestroy, DirectiveNoHooks)).toBe(false);
|
2015-05-27 08:08:14 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
describe('ngOnInit', () => {
|
|
|
|
|
it('should be true when the directive has the ngOnInit method', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnInit, DirectiveWithOnInitMethod)).toBe(true);
|
2015-05-27 10:14:37 -07:00
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
it('should be false otherwise', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.OnInit, DirectiveNoHooks)).toBe(false);
|
2015-08-14 10:03:45 -07:00
|
|
|
});
|
2015-05-27 10:14:37 -07:00
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
describe('ngDoCheck', () => {
|
|
|
|
|
it('should be true when the directive has the ngDoCheck method', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.DoCheck, DirectiveWithOnCheckMethod)).toBe(true);
|
2015-05-27 10:14:37 -07:00
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
it('should be false otherwise', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.DoCheck, DirectiveNoHooks)).toBe(false);
|
2015-08-14 10:03:45 -07:00
|
|
|
});
|
2015-05-27 10:14:37 -07:00
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
describe('ngAfterContentInit', () => {
|
|
|
|
|
it('should be true when the directive has the ngAfterContentInit method', () => {
|
|
|
|
|
expect(hasLifecycleHook(
|
|
|
|
|
LifecycleHooks.AfterContentInit, DirectiveWithAfterContentInitMethod))
|
2015-08-28 18:11:04 -07:00
|
|
|
.toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
it('should be false otherwise', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterContentInit, DirectiveNoHooks)).toBe(false);
|
2015-08-28 18:11:04 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
describe('ngAfterContentChecked', () => {
|
|
|
|
|
it('should be true when the directive has the ngAfterContentChecked method', () => {
|
|
|
|
|
expect(hasLifecycleHook(
|
|
|
|
|
LifecycleHooks.AfterContentChecked, DirectiveWithAfterContentCheckedMethod))
|
2015-05-27 08:08:14 -07:00
|
|
|
.toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
it('should be false otherwise', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterContentChecked, DirectiveNoHooks))
|
2015-08-14 10:03:45 -07:00
|
|
|
.toBe(false);
|
2015-05-27 08:08:14 -07:00
|
|
|
});
|
|
|
|
|
});
|
2015-08-28 18:11:04 -07:00
|
|
|
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
describe('ngAfterViewInit', () => {
|
|
|
|
|
it('should be true when the directive has the ngAfterViewInit method', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit, DirectiveWithAfterViewInitMethod))
|
2015-08-28 18:11:04 -07:00
|
|
|
.toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
it('should be false otherwise', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterViewInit, DirectiveNoHooks)).toBe(false);
|
2015-08-28 18:11:04 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
describe('ngAfterViewChecked', () => {
|
|
|
|
|
it('should be true when the directive has the ngAfterViewChecked method', () => {
|
|
|
|
|
expect(hasLifecycleHook(
|
|
|
|
|
LifecycleHooks.AfterViewChecked, DirectiveWithAfterViewCheckedMethod))
|
2015-08-28 18:11:04 -07:00
|
|
|
.toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
it('should be false otherwise', () => {
|
2015-10-01 20:47:49 -07:00
|
|
|
expect(hasLifecycleHook(LifecycleHooks.AfterViewChecked, DirectiveNoHooks)).toBe(false);
|
2015-08-28 18:11:04 -07:00
|
|
|
});
|
|
|
|
|
});
|
2015-05-27 08:08:14 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DirectiveNoHooks {}
|
|
|
|
|
|
2015-08-27 21:19:56 -07:00
|
|
|
class DirectiveWithOnChangesMethod {
|
2016-06-08 15:45:15 -07:00
|
|
|
ngOnChanges(_: any /** TODO #9100 */) {}
|
2015-05-27 08:08:14 -07:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 10:14:37 -07:00
|
|
|
class DirectiveWithOnInitMethod {
|
2015-11-16 17:04:36 -08:00
|
|
|
ngOnInit() {}
|
2015-05-27 10:14:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DirectiveWithOnCheckMethod {
|
2015-11-16 17:04:36 -08:00
|
|
|
ngDoCheck() {}
|
2015-05-27 10:14:37 -07:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 08:08:14 -07:00
|
|
|
class DirectiveWithOnDestroyMethod {
|
2015-11-16 17:04:36 -08:00
|
|
|
ngOnDestroy() {}
|
2015-05-27 08:08:14 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-28 18:11:04 -07:00
|
|
|
class DirectiveWithAfterContentInitMethod {
|
2015-11-16 17:04:36 -08:00
|
|
|
ngAfterContentInit() {}
|
2015-08-28 18:11:04 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-27 21:19:56 -07:00
|
|
|
class DirectiveWithAfterContentCheckedMethod {
|
2015-11-16 17:04:36 -08:00
|
|
|
ngAfterContentChecked() {}
|
2015-07-04 15:04:50 +02:00
|
|
|
}
|
2015-08-28 18:11:04 -07:00
|
|
|
|
|
|
|
|
class DirectiveWithAfterViewInitMethod {
|
2015-11-16 17:04:36 -08:00
|
|
|
ngAfterViewInit() {}
|
2015-08-28 18:11:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DirectiveWithAfterViewCheckedMethod {
|
2015-11-16 17:04:36 -08:00
|
|
|
ngAfterViewChecked() {}
|
2015-08-28 18:11:04 -07:00
|
|
|
}
|