Skip to content

Commit

Permalink
fix(directive): check undefined/null inputs/outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanfield committed Jun 2, 2017
1 parent df6b8f1 commit d31df71
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/dynamic/dynamic.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ describe('Directive: Dynamic', () => {
delete injectedComp.ngOnChanges;
expect(() => fixture.detectChanges()).not.toThrow();
});

it('should NOT throw exception if inputs undefined', () => {
fixture.componentInstance['inputs'] = undefined;
expect(() => fixture.detectChanges()).not.toThrow();
});

it('should NOT throw exception if inputs null', () => {
fixture.componentInstance['inputs'] = null;
expect(() => fixture.detectChanges()).not.toThrow();
});
});

describe('inputs with `NgComponentOutlet`', () => {
Expand Down Expand Up @@ -156,6 +166,26 @@ describe('Directive: Dynamic', () => {
expect(outputSpy).toHaveBeenCalledWith('data');
}));

it('should NOT bind outputs to component when outputs undefined', async(() => {
fixture.componentInstance['outputs'] = undefined;

expect(() => fixture.detectChanges()).not.toThrow();

injectedComp.onEvent.next('data');

expect(outputSpy).not.toHaveBeenCalled();
}));

it('should NOT bind outputs to component when outputs null', async(() => {
fixture.componentInstance['outputs'] = null;

expect(() => fixture.detectChanges()).not.toThrow();

injectedComp.onEvent.next('data');

expect(outputSpy).not.toHaveBeenCalled();
}));

it('should unbind outputs when component destroys', () => {
const tearDownFn = jasmine.createSpy('tearDownFn');

Expand Down
4 changes: 2 additions & 2 deletions src/dynamic/dynamic.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class DynamicDirective implements OnChanges, DoCheck, OnDestroy {
}

updateInputs(isFirstChange = false) {
if (!this._componentInst) {
if (!this.ndcDynamicInputs || !this._componentInst) {
return;
}

Expand All @@ -101,7 +101,7 @@ export class DynamicDirective implements OnChanges, DoCheck, OnDestroy {
bindOutputs() {
this._destroyed$.next();

if (!this._componentInst) {
if (!this.ndcDynamicOutputs || !this._componentInst) {
return;
}

Expand Down

0 comments on commit d31df71

Please sign in to comment.