diff --git a/lib/mock_component.spec.ts b/lib/mock_component.spec.ts index ff294c810b..45650cfdb1 100644 --- a/lib/mock_component.spec.ts +++ b/lib/mock_component.spec.ts @@ -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' @@ -11,6 +12,13 @@ export class ExampleComponent { @Output() someOutput: EventEmitter; } +@Component({ + selector: 'empty-component', + template: 'some template' +}) +export class EmptyComponent {} +/* tslint:enable:max-classes-per-file */ + describe('MockComponent', () => { let exampleComponent: any; @@ -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([]); }); }); diff --git a/lib/mock_component.ts b/lib/mock_component.ts index 97b9e43d7e..d7e2077fad 100644 --- a/lib/mock_component.ts +++ b/lib/mock_component.ts @@ -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 {}; }