fix(dart): don't instantiate abstract directive.
Directive is an abstract class, so it should not be instantiated directly in tests.
This commit is contained in:
parent
123ee8e06f
commit
136f64f4ac
|
@ -1,21 +1,25 @@
|
||||||
import {ddescribe, describe, it, iit, expect, beforeEach} from 'angular2/test_lib';
|
import {ddescribe, describe, it, iit, expect, beforeEach} from 'angular2/test_lib';
|
||||||
import {Directive, onChange} from 'angular2/src/core/annotations/annotations';
|
import {Directive, onChange} from 'angular2/src/core/annotations/annotations';
|
||||||
|
|
||||||
|
class DummyDirective extends Directive {
|
||||||
|
constructor({lifecycle = []} = {}) { super({lifecycle}); }
|
||||||
|
}
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe("Directive", () => {
|
describe("Directive", () => {
|
||||||
describe("lifecycle", () => {
|
describe("lifecycle", () => {
|
||||||
it("should be false when no lifecycle specified", () => {
|
it("should be false when no lifecycle specified", () => {
|
||||||
var d = new Directive();
|
var d = new DummyDirective();
|
||||||
expect(d.hasLifecycleHook(onChange)).toBe(false);
|
expect(d.hasLifecycleHook(onChange)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be false when the lifecycle does not contain the hook", () => {
|
it("should be false when the lifecycle does not contain the hook", () => {
|
||||||
var d = new Directive({lifecycle:[]});
|
var d = new DummyDirective({lifecycle:[]});
|
||||||
expect(d.hasLifecycleHook(onChange)).toBe(false);
|
expect(d.hasLifecycleHook(onChange)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be true otherwise", () => {
|
it("should be true otherwise", () => {
|
||||||
var d = new Directive({lifecycle:[onChange]});
|
var d = new DummyDirective({lifecycle:[onChange]});
|
||||||
expect(d.hasLifecycleHook(onChange)).toBe(true);
|
expect(d.hasLifecycleHook(onChange)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,8 @@ import {LightDom, DestinationLightDom} from 'angular2/src/core/compiler/shadow_d
|
||||||
import {Directive} from 'angular2/src/core/annotations/annotations';
|
import {Directive} from 'angular2/src/core/annotations/annotations';
|
||||||
import {BindingPropagationConfig} from 'angular2/change_detection';
|
import {BindingPropagationConfig} from 'angular2/change_detection';
|
||||||
|
|
||||||
|
class DummyDirective extends Directive { constructor({lifecycle}) { super({lifecycle}); } }
|
||||||
|
|
||||||
@proxy
|
@proxy
|
||||||
@IMPLEMENTS(View)
|
@IMPLEMENTS(View)
|
||||||
class DummyView extends SpyObject {noSuchMethod(m){super.noSuchMethod(m)}}
|
class DummyView extends SpyObject {noSuchMethod(m){super.noSuchMethod(m)}}
|
||||||
|
@ -445,10 +447,10 @@ export function main() {
|
||||||
'(A_Needs_B -> B_Needs_A -> A_Needs_B)');
|
'(A_Needs_B -> B_Needs_A -> A_Needs_B)');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should call onDestroy on directives subscribed to this event", function () {
|
it("should call onDestroy on directives subscribed to this event", function() {
|
||||||
var inj = injector([
|
var inj = injector([DirectiveBinding.createFromType(
|
||||||
DirectiveBinding.createFromType(DirectiveWithDestroy, new Directive({lifecycle: [onDestroy]}))
|
DirectiveWithDestroy,
|
||||||
]);
|
new DummyDirective({lifecycle: [onDestroy]}))]);
|
||||||
var destroy = inj.get(DirectiveWithDestroy);
|
var destroy = inj.get(DirectiveWithDestroy);
|
||||||
inj.clearDirectives();
|
inj.clearDirectives();
|
||||||
expect(destroy.onDestroyCounter).toBe(1);
|
expect(destroy.onDestroyCounter).toBe(1);
|
||||||
|
@ -524,7 +526,9 @@ export function main() {
|
||||||
|
|
||||||
it("should support rehydrating the private component", () => {
|
it("should support rehydrating the private component", () => {
|
||||||
var inj = injector([]);
|
var inj = injector([]);
|
||||||
inj.createPrivateComponent(DirectiveWithDestroy, new Directive({lifecycle: [onDestroy]}));
|
inj.createPrivateComponent(
|
||||||
|
DirectiveWithDestroy,
|
||||||
|
new DummyDirective({lifecycle: [onDestroy]}));
|
||||||
var dir = inj.getPrivateComponent();
|
var dir = inj.getPrivateComponent();
|
||||||
|
|
||||||
inj.clearDirectives();
|
inj.clearDirectives();
|
||||||
|
|
|
@ -17,6 +17,10 @@ import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone';
|
||||||
import {EventManager, DomEventsPlugin} from 'angular2/src/core/events/event_manager';
|
import {EventManager, DomEventsPlugin} from 'angular2/src/core/events/event_manager';
|
||||||
import {reflector} from 'angular2/src/reflection/reflection';
|
import {reflector} from 'angular2/src/reflection/reflection';
|
||||||
|
|
||||||
|
class DummyDirective extends Directive {
|
||||||
|
constructor({lifecycle = []}) { super({lifecycle}); }
|
||||||
|
}
|
||||||
|
|
||||||
@proxy
|
@proxy
|
||||||
@IMPLEMENTS(ViewContainer)
|
@IMPLEMENTS(ViewContainer)
|
||||||
class FakeViewContainer {
|
class FakeViewContainer {
|
||||||
|
@ -587,7 +591,8 @@ export function main() {
|
||||||
new DynamicProtoChangeDetector(null), null);
|
new DynamicProtoChangeDetector(null), null);
|
||||||
|
|
||||||
pv.bindElement(null, 0, new ProtoElementInjector(null, 0, [
|
pv.bindElement(null, 0, new ProtoElementInjector(null, 0, [
|
||||||
DirectiveBinding.createFromType(DirectiveImplementingOnChange, new Directive({lifecycle: [onChange]}))
|
DirectiveBinding.createFromType(DirectiveImplementingOnChange,
|
||||||
|
new DummyDirective({lifecycle: [onChange]}))
|
||||||
]));
|
]));
|
||||||
pv.bindDirectiveProperty( 0, parser.parseBinding('a', null), 'a', reflector.setter('a'));
|
pv.bindDirectiveProperty( 0, parser.parseBinding('a', null), 'a', reflector.setter('a'));
|
||||||
pv.bindDirectiveProperty( 0, parser.parseBinding('b', null), 'b', reflector.setter('b'));
|
pv.bindDirectiveProperty( 0, parser.parseBinding('b', null), 'b', reflector.setter('b'));
|
||||||
|
@ -606,7 +611,8 @@ export function main() {
|
||||||
new DynamicProtoChangeDetector(null), null);
|
new DynamicProtoChangeDetector(null), null);
|
||||||
|
|
||||||
pv.bindElement(null, 0, new ProtoElementInjector(null, 0, [
|
pv.bindElement(null, 0, new ProtoElementInjector(null, 0, [
|
||||||
DirectiveBinding.createFromType(DirectiveImplementingOnChange, new Directive({lifecycle: [onChange]}))
|
DirectiveBinding.createFromType(DirectiveImplementingOnChange,
|
||||||
|
new DummyDirective({lifecycle: [onChange]}))
|
||||||
]));
|
]));
|
||||||
pv.bindDirectiveProperty( 0, parser.parseBinding('a', null), 'a', reflector.setter('a'));
|
pv.bindDirectiveProperty( 0, parser.parseBinding('a', null), 'a', reflector.setter('a'));
|
||||||
pv.bindDirectiveProperty( 0, parser.parseBinding('b', null), 'b', reflector.setter('b'));
|
pv.bindDirectiveProperty( 0, parser.parseBinding('b', null), 'b', reflector.setter('b'));
|
||||||
|
@ -633,7 +639,8 @@ export function main() {
|
||||||
new DynamicProtoChangeDetector(null), null);
|
new DynamicProtoChangeDetector(null), null);
|
||||||
|
|
||||||
pv.bindElement(null, 0, new ProtoElementInjector(null, 0, [
|
pv.bindElement(null, 0, new ProtoElementInjector(null, 0, [
|
||||||
DirectiveBinding.createFromType(DirectiveImplementingOnAllChangesDone, new Directive({lifecycle: [onAllChangesDone]}))
|
DirectiveBinding.createFromType(DirectiveImplementingOnAllChangesDone,
|
||||||
|
new DummyDirective({lifecycle: [onAllChangesDone]}))
|
||||||
]));
|
]));
|
||||||
|
|
||||||
createViewAndChangeDetector(pv);
|
createViewAndChangeDetector(pv);
|
||||||
|
|
Loading…
Reference in New Issue