How to use the ng-mocks.MockDeclaration function in ng-mocks

To help you get started, we’ve selected a few ng-mocks examples, based on popular ways it is used in public projects.

github getsaf / shallow-render / lib / tools / ng-mock.ts View on Github external
// tslint:disable-next-line no-unnecessary-type-assertion
    return setup.mockCache.add(thing, thing.map(t => ngMock(t, setup))) as any; // Recursion
  }

  if (setup.dontMock.includes(thing) || (isModuleWithProviders(thing) && setup.dontMock.includes(thing.ngModule))) {
    return thing;
  }

  let mock: NgMockable;
  try {
    if (ngModuleResolver.isNgModule(thing) || isModuleWithProviders(thing)) {
      mock = mockModule(thing, setup);
    } else if (isPipeTransform(thing)) {
      mock = MockPipe(thing as Type<any>, setup.mockPipes.get(thing));
    } else if (typeof thing === 'function') { // tslint:disable-line strict-type-predicates
      mock = MockDeclaration(thing as Type<any>);
      if (
        setup.withStructuralDirectives.get(thing as Type<any>)
        || (setup.alwaysRenderStructuralDirectives && setup.withStructuralDirectives.get(thing as Type<any>) !== false)
      ) {
        mock.prototype.ngOnInit = () => undefined;
        testFramework.spyOn(mock.prototype, 'ngOnInit', function() {
          // tslint:disable-next-line: no-empty
          try { this.__render(); } catch (e) { }
        });
      }
      fixEmptySelector(thing as Type<any>, mock);
      const stubs = setup.mocks.get(thing);
      if (stubs) {
        mock = class extends (mock as Type<any>) {
          constructor() {
            super();

ng-mocks

An Angular testing library for creating mock services, components, directives, pipes and modules in unit tests. It provides shallow rendering, precise stubs to fake child dependencies. ng-mocks works with Angular 5 6 7 8 9 10 11 12 13 14 15, jasmine and j

MIT
Latest version published 4 days ago

Package Health Score

89 / 100
Full package analysis

Similar packages