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);
@ -484,7 +486,7 @@ export function main() {
expect(inj.get(BindingPropagationConfig)).toEqual(config);
});
});
describe("createPrivateComponent", () => {
it("should create a private component", () => {
var inj = injector([]);
@ -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();
@ -537,7 +541,7 @@ export function main() {
expect(inj.getPrivateComponent()).not.toBe(null);
});
});
describe('event emitters', () => {
it('should be injectable and callable', () => {
var called = false;

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 {
@ -351,7 +355,7 @@ export function main() {
el('<div dec class="ng-binding">hello shadow dom</div>'),
new DynamicProtoChangeDetector(null),
null);
subpv.bindElement(null, 0,
subpv.bindElement(null, 0,
new ProtoElementInjector(null, 0, [ServiceDependentDecorator]));
var pv = createComponentWithSubPV(subpv);
@ -376,7 +380,7 @@ export function main() {
el('<div dec class="ng-binding">hello shadow dom</div>'),
new DynamicProtoChangeDetector(null),
null);
subpv.bindElement(null, 0,
subpv.bindElement(null, 0,
new ProtoElementInjector(null, 0, [ServiceDependentDecorator]));
var pv = createComponentWithSubPV(subpv);
@ -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'));
@ -627,13 +633,14 @@ export function main() {
cd.detectChanges();
expect(directive.changes).toEqual({"a" : new PropertyUpdate(100, 0)});
});
it('should invoke the onAllChangesDone callback', () => {
var pv = new ProtoView(el('<div class="ng-binding"></div>'),
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);