šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

ng2-mock-component

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng2-mock-component

An Angular 2 module for mocking components.

0.2.0
latest
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
Ā 
Created
Source

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)

Keywords

angular

FAQs

Package last updated on 15 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts