Skip to content

Commit

Permalink
fix: works with component w/o inputs or outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ike18t committed Nov 14, 2017
1 parent 385c9c4 commit b3d38e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions lib/mock_component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, EventEmitter, Input, Output } from '@angular/core';
import 'reflect-metadata';
import { MockComponent } from './mock_component';

/* tslint:disable:max-classes-per-file */
@Component({
selector: 'example-component',
template: 'some template'
Expand All @@ -11,6 +12,13 @@ export class ExampleComponent {
@Output() someOutput: EventEmitter<boolean>;
}

@Component({
selector: 'empty-component',
template: 'some template'
})
export class EmptyComponent {}
/* tslint:enable:max-classes-per-file */

describe('MockComponent', () => {
let exampleComponent: any;

Expand Down Expand Up @@ -73,15 +81,10 @@ describe('MockComponent', () => {
});
});

it('should throw error if component doesn\'t have annotations', () => {
delete exampleComponent.decorators;
expect(() => MockComponent(exampleComponent))
.toThrowError(Error, 'No annotation or decoration metadata on your component');
});

it('should throw error if component doesn\'t have property metadata', () => {
delete exampleComponent.propDecorators;
expect(() => MockComponent(exampleComponent))
.toThrowError(Error, 'No property metadata on your component');
it('should work with a component w/o inputs or outputs', () => {
const mockedComponent = MockComponent(EmptyComponent);
const annotations = Reflect.getMetadata('annotations', mockedComponent)[0];
expect(annotations.inputs).toEqual([]);
expect(annotations.outputs).toEqual([]);
});
});
2 changes: 1 addition & 1 deletion lib/mock_component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ function getPropertyMetadata(component: any): any {
if (Reflect.hasMetadata('propMetadata', component)) {
return Reflect.getMetadata('propMetadata', component);
}
throw new Error('No property metadata on your component');
return {};
}

0 comments on commit b3d38e7

Please sign in to comment.