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:
Martin Probst 2015-03-30 17:26:22 -07:00
parent 123ee8e06f
commit 136f64f4ac
3 changed files with 31 additions and 16 deletions

View File

@ -1,21 +1,25 @@
import {ddescribe, describe, it, iit, expect, beforeEach} from 'angular2/test_lib';
import {Directive, onChange} from 'angular2/src/core/annotations/annotations';
class DummyDirective extends Directive {
constructor({lifecycle = []} = {}) { super({lifecycle}); }
}
export function main() {
describe("Directive", () => {
describe("lifecycle", () => {
it("should be false when no lifecycle specified", () => {
var d = new Directive();
var d = new DummyDirective();
expect(d.hasLifecycleHook(onChange)).toBe(false);
});
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);
});
it("should be true otherwise", () => {
var d = new Directive({lifecycle:[onChange]});
var d = new DummyDirective({lifecycle:[onChange]});
expect(d.hasLifecycleHook(onChange)).toBe(true);
});
});

View File

@ -14,6 +14,8 @@ import {LightDom, DestinationLightDom} from 'angular2/src/core/compiler/shadow_d
import {Directive} from 'angular2/src/core/annotations/annotations';
import {BindingPropagationConfig} from 'angular2/change_detection';
class DummyDirective extends Directive { constructor({lifecycle}) { super({lifecycle}); } }
@proxy
@IMPLEMENTS(View)
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)');
});
it("should call onDestroy on directives subscribed to this event", function () {
var inj = injector([
DirectiveBinding.createFromType(DirectiveWithDestroy, new Directive({lifecycle: [onDestroy]}))
]);
it("should call onDestroy on directives subscribed to this event", function() {
var inj = injector([DirectiveBinding.createFromType(
DirectiveWithDestroy,
new DummyDirective({lifecycle: [onDestroy]}))]);
var destroy = inj.get(DirectiveWithDestroy);
inj.clearDirectives();
expect(destroy.onDestroyCounter).toBe(1);
@ -524,7 +526,9 @@ export function main() {
it("should support rehydrating the private component", () => {
var inj = injector([]);
inj.createPrivateComponent(DirectiveWithDestroy, new Directive({lifecycle: [onDestroy]}));
inj.createPrivateComponent(
DirectiveWithDestroy,
new DummyDirective({lifecycle: [onDestroy]}));
var dir = inj.getPrivateComponent();
inj.clearDirectives();

View File

@ -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 {reflector} from 'angular2/src/reflection/reflection';
class DummyDirective extends Directive {
constructor({lifecycle = []}) { super({lifecycle}); }
}
@proxy
@IMPLEMENTS(ViewContainer)
class FakeViewContainer {
@ -587,7 +591,8 @@ export function main() {
new DynamicProtoChangeDetector(null), null);
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('b', null), 'b', reflector.setter('b'));
@ -606,7 +611,8 @@ export function main() {
new DynamicProtoChangeDetector(null), null);
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('b', null), 'b', reflector.setter('b'));
@ -633,7 +639,8 @@ export function main() {
new DynamicProtoChangeDetector(null), null);
pv.bindElement(null, 0, new ProtoElementInjector(null, 0, [
DirectiveBinding.createFromType(DirectiveImplementingOnAllChangesDone, new Directive({lifecycle: [onAllChangesDone]}))
DirectiveBinding.createFromType(DirectiveImplementingOnAllChangesDone,
new DummyDirective({lifecycle: [onAllChangesDone]}))
]));
createViewAndChangeDetector(pv);