https://github.com/cnunciato/ng-mock-component
An Angular module for mocking components.
https://github.com/cnunciato/ng-mock-component
angular angular2 mocking-components
Last synced: 11 months ago
JSON representation
An Angular module for mocking components.
- Host: GitHub
- URL: https://github.com/cnunciato/ng-mock-component
- Owner: cnunciato
- License: mit
- Created: 2016-12-25T21:44:51.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-08-15T02:14:00.000Z (almost 7 years ago)
- Last Synced: 2025-04-04T01:11:08.535Z (over 1 year ago)
- Topics: angular, angular2, mocking-components
- Language: TypeScript
- Homepage:
- Size: 7.81 KB
- Stars: 53
- Watchers: 2
- Forks: 13
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ng2-mock-component
A very simple Angular 2 module for mocking components in unit tests.
```
npm install --save-dev ng2-mock-component
```
## Usage
Just specify the `selector` of the component you wish to mock (along with whatever other
[metadata properties](https://angular.io/docs/ts/latest/api/core/index/Component-decorator.html)
you like), and `MockComponent` will supply that component with an empty template (unless you provide
a template string, in which case, it'll use that instead).
```
import { TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { MyComponent } from './src/my.component';
import { MockComponent } from 'ng2-mock-component';
describe('MyComponent', () => {
let fixture, element;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
MyComponent,
MockComponent({ selector: 'my-subcomponent' })
]
});
fixture = TestBed.createComponent(MyComponent);
element = fixture.debugElement;
});
it('works', () => {
fixture.detectChanges();
expect(element.query(By.css('my-subcomponent'))).not.toBeNull();
});
});
```
## Author
Christian Nunciato (chris@nunciato.org)