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.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

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, setup.mockPipes.get(thing));
    } else if (typeof thing === 'function') { // tslint:disable-line strict-type-predicates
      mock = MockDeclaration(thing as Type);
      if (
        setup.withStructuralDirectives.get(thing as Type)
        || (setup.alwaysRenderStructuralDirectives && setup.withStructuralDirectives.get(thing as Type) !== 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, mock);
      const stubs = setup.mocks.get(thing);
      if (stubs) {
        mock = class extends (mock as Type) {
          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 16 17, jasmine

MIT
Latest version published 6 days ago

Package Health Score

89 / 100
Full package analysis