JSPM

  • Created
  • Published
  • Downloads 469137
  • Score
    100M100P100Q194817F
  • License MIT

An Angular testing library for creating mock services, components, directives, pipes and modules in unit tests, which includes shallow rendering, precise stubs to dump child dependencies, supports Angular 5 6 7 8 9 10 11, jasmine and jest.

Package Exports

  • ng-mocks

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ng-mocks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

chat on gitter npm version build status coverage status language grade

Mock components, services and more out of annoying dependencies in Angular tests

ng-mocks helps to:

  • mock Components, Directives, Pipes, Modules, Services and Tokens
  • facilitate boilerplate in tests
  • access declarations via simple interface

The current version of the library has been tested and can be used with:

  • Angular 11 (Jasmine, Jest, Ivy, es5, es2015)
  • Angular 10 (Jasmine, Jest, Ivy, es5, es2015)
  • Angular 9 (Jasmine, Jest, Ivy, es5, es2015)
  • Angular 8 (Jasmine, Jest, es5, es2015)
  • Angular 7 (Jasmine, Jest, es5, es2015)
  • Angular 6 (Jasmine, Jest, es5, es2015)
  • Angular 5 (Jasmine, Jest, es5, es2015)

Very short introduction

describe('app-component', () => {
  // Mocking everything in AppModule except AppComponent
  beforeEach(() => MockBuilder(AppComponent, AppModule));

  // Mocking observables in dependencies
  beforeEach(() =>
    MockInstance(AuthService, () => ({
      isLoggedIn$: EMPTY,
      currentUser$: EMPTY,
    })),
  );

  it('should be created', () => {
    const fixture = MockRender(AppComponent);
    expect(fixture.point.componentInstance).toBeDefined();
  });
});

Profit.

Extra

Please support, if you like it:

Thank you!

P.S. Feel free to contact us if you need help.