0.2.0 • Published 5 years ago

ng2-mock-component v0.2.0

Weekly downloads
6,529
License
MIT
Repository
-
Last release
5 years ago

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 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)

0.2.0

5 years ago

0.1.1

6 years ago

0.1.0

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago