UNPKG

shallow-render

Version:

Shallow rendering test utility for Angular

48 lines 2.25 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TestSetup = void 0; const core_1 = require("@angular/core"); const reflect_1 = require("../tools/reflect"); const mock_cache_1 = require("./mock-cache"); /** * An empty module used to test Standalone components */ let EmptyModule = class EmptyModule { }; EmptyModule = __decorate([ (0, core_1.NgModule)({}) ], EmptyModule); class TestSetup { constructor(testComponentOrService, testModule = EmptyModule) { this.testComponentOrService = testComponentOrService; this.testModule = testModule; this.dontMock = [this.testComponentOrService]; this.mocks = new Map(); this.staticMocks = new Map(); this.moduleReplacements = new Map(); // eslint-disable-next-line @typescript-eslint/ban-types this.mockPipes = new Map(); this.mockCache = new mock_cache_1.MockCache(); this.providers = []; this.declarations = []; this.imports = []; this.withStructuralDirectives = new Map(); this.alwaysRenderStructuralDirectives = false; const isStandalone = reflect_1.reflect.isStandalone(testComponentOrService); const hasModule = testModule !== EmptyModule; if (isStandalone && hasModule) { throw new Error(`Do not specify a module when testing ${testComponentOrService.name} (because it is marked as "standalone")`); } if (!isStandalone && !hasModule) { throw new Error(`A module must be specified when testing ${testComponentOrService.name}`); } } } exports.TestSetup = TestSetup; //# sourceMappingURL=test-setup.js.map