feat(dart): Add a dev-mode check for undeclared lifecycle interfaces
Add a check in `ReflectionCapabilities#interfaces` which determines if the passed-in type implements a Lifecycle Interface but does not declare that it does so. See https://goo.gl/b07Kii for details. Closes #6849
This commit is contained in:
committed by
Vikram Subramanian
parent
bc9644e86e
commit
a3d7629134
@@ -7,6 +7,7 @@ import {
|
||||
beforeEach,
|
||||
browserDetection
|
||||
} from 'angular2/testing_internal';
|
||||
import {OnInit} from 'angular2/core';
|
||||
import {Reflector, ReflectionInfo} from 'angular2/src/core/reflection/reflection';
|
||||
import {ReflectionCapabilities} from 'angular2/src/core/reflection/reflection_capabilities';
|
||||
import {
|
||||
@@ -65,6 +66,19 @@ class SuperClassImplementingInterface implements Interface2 {}
|
||||
|
||||
class ClassImplementingInterface extends SuperClassImplementingInterface implements Interface {}
|
||||
|
||||
// Classes used to test our runtime check for classes that implement lifecycle interfaces but do not
|
||||
// declare them.
|
||||
// See https://github.com/angular/angular/pull/6879 and https://goo.gl/b07Kii for details.
|
||||
class ClassDoesNotDeclareOnInit {
|
||||
ngOnInit() {}
|
||||
}
|
||||
|
||||
class SuperClassImplementingOnInit implements OnInit {
|
||||
ngOnInit() {}
|
||||
}
|
||||
|
||||
class SubClassDoesNotDeclareOnInit extends SuperClassImplementingOnInit {}
|
||||
|
||||
export function main() {
|
||||
describe('Reflector', () => {
|
||||
var reflector;
|
||||
@@ -214,6 +228,14 @@ export function main() {
|
||||
var p = reflector.interfaces(ClassWithDecorators);
|
||||
expect(p).toEqual([]);
|
||||
});
|
||||
|
||||
it("should throw for undeclared lifecycle interfaces",
|
||||
() => { expect(() => reflector.interfaces(ClassDoesNotDeclareOnInit)).toThrowError(); });
|
||||
|
||||
it("should throw for class inheriting a lifecycle impl and not declaring the interface",
|
||||
() => {
|
||||
expect(() => reflector.interfaces(SubClassDoesNotDeclareOnInit)).toThrowError();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user