Skip to content

Commit

Permalink
feat(mocks): add mock component function
Browse files Browse the repository at this point in the history
  • Loading branch information
Netanel Basal committed May 22, 2018
1 parent a575bb9 commit ce20d26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './service';
export * from './spectator';
export * from './type-in-element';
export * from './globals';
export * from './mock-component';
25 changes: 25 additions & 0 deletions src/lib/src/mock-component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component, EventEmitter } from '@angular/core';

/**
* Examples:
* MockComponent({ selector: 'some-component' });
* MockComponent({ selector: 'some-component', inputs: ['some-input', 'some-other-input'] });
*
*/
export function MockComponent(options: Component): Component {
const metadata: Component = {
selector: options.selector,
template: options.template || '',
inputs: options.inputs,
outputs: options.outputs || [],
exportAs: options.exportAs || ''
};

class Mock {}

metadata.outputs.forEach(method => {
Mock.prototype[method] = new EventEmitter<any>();
});

return Component(metadata)(Mock as any);
}

0 comments on commit ce20d26

Please sign in to comment.