How to use ngModule method in storybook-root

Best JavaScript code snippet using storybook-root

scope_spec.ts

Source:scope_spec.ts Github

copy

Full Screen

1/**2 * @license3 * Copyright Google Inc. All Rights Reserved.4 *5 * Use of this source code is governed by an MIT-style license that can be6 * found in the LICENSE file at https://angular.io/license7 */8import {Diagnostic} from '@angular/compiler-cli';9import * as ts from 'typescript';10import {ErrorCode, ngErrorCode} from '../../src/ngtsc/diagnostics';11import {runInEachFileSystem} from '../../src/ngtsc/file_system/testing';12import {getTokenAtPosition} from '../../src/ngtsc/util/src/typescript';13import {loadStandardTestFiles} from '../helpers/src/mock_file_loading';14import {NgtscTestEnvironment} from './env';15const testFiles = loadStandardTestFiles();16runInEachFileSystem(() => {17 describe('ngtsc module scopes', () => {18 let env !: NgtscTestEnvironment;19 beforeEach(() => {20 env = NgtscTestEnvironment.setup(testFiles);21 env.tsconfig();22 });23 describe('diagnostics', () => {24 describe('declarations', () => {25 it('should detect when a random class is declared', () => {26 env.write('test.ts', `27 import {NgModule} from '@angular/core';28 export class RandomClass {}29 @NgModule({30 declarations: [RandomClass],31 })32 export class Module {}33 `);34 const diags = env.driveDiagnostics();35 expect(diags.length).toBe(1);36 const node = diagnosticToNode(diags[0], ts.isIdentifier);37 expect(node.text).toEqual('RandomClass');38 expect(diags[0].messageText).toContain('is not a directive, a component, or a pipe.');39 });40 it('should detect when a declaration lives outside the current compilation', () => {41 env.write('dir.d.ts', `42 import {ɵɵDirectiveDefWithMeta} from '@angular/core';43 export declare class ExternalDir {44 static ɵdir: ɵɵDirectiveDefWithMeta<ExternalDir, '[test]', never, never, never, never>;45 }46 `);47 env.write('test.ts', `48 import {NgModule} from '@angular/core';49 import {ExternalDir} from './dir';50 @NgModule({51 declarations: [ExternalDir],52 })53 export class Module {}54 `);55 const diags = env.driveDiagnostics();56 expect(diags.length).toBe(1);57 const node = diagnosticToNode(diags[0], ts.isIdentifier);58 expect(node.text).toEqual('ExternalDir');59 expect(diags[0].messageText).toContain(`not a part of the current compilation`);60 });61 it('should detect when a declaration is shared between two modules', () => {62 env.write('test.ts', `63 import {Directive, NgModule} from '@angular/core';64 @Directive({selector: '[test]'})65 export class TestDir {}66 @NgModule({67 declarations: [TestDir]68 })69 export class ModuleA {}70 @NgModule({71 declarations: [TestDir],72 })73 export class ModuleB {}74 `);75 const diags = env.driveDiagnostics();76 expect(diags.length).toBe(1);77 const node = findContainingClass(diagnosticToNode(diags[0], ts.isIdentifier));78 expect(node.name !.text).toEqual('TestDir');79 const relatedNodes = new Set(diags[0].relatedInformation !.map(80 related =>81 findContainingClass(diagnosticToNode(related, ts.isIdentifier)).name !.text));82 expect(relatedNodes).toContain('ModuleA');83 expect(relatedNodes).toContain('ModuleB');84 expect(relatedNodes.size).toBe(2);85 });86 it('should detect when a declaration is repeated within the same module', () => {87 env.write('test.ts', `88 import {Directive, NgModule} from '@angular/core';89 @Directive({selector: '[test]'})90 export class TestDir {}91 @NgModule({92 declarations: [TestDir, TestDir],93 })94 export class Module {}95 `);96 const diags = env.driveDiagnostics();97 expect(diags.length).toBe(0);98 });99 it('should detect when a declaration is shared between two modules, and is repeated within them',100 () => {101 env.write('test.ts', `102 import {Directive, NgModule} from '@angular/core';103 @Directive({selector: '[test]'})104 export class TestDir {}105 @NgModule({106 declarations: [TestDir, TestDir]107 })108 export class ModuleA {}109 @NgModule({110 declarations: [TestDir, TestDir],111 })112 export class ModuleB {}113 `);114 const diags = env.driveDiagnostics();115 expect(diags.length).toBe(1);116 const node = findContainingClass(diagnosticToNode(diags[0], ts.isIdentifier));117 expect(node.name !.text).toEqual('TestDir');118 const relatedNodes = new Set(diags[0].relatedInformation !.map(119 related =>120 findContainingClass(diagnosticToNode(related, ts.isIdentifier)).name !.text));121 expect(relatedNodes).toContain('ModuleA');122 expect(relatedNodes).toContain('ModuleB');123 expect(relatedNodes.size).toBe(2);124 });125 });126 describe('imports', () => {127 it('should emit imports in a pure function call', () => {128 env.write('test.ts', `129 import {NgModule} from '@angular/core';130 @NgModule({})131 export class OtherModule {}132 @NgModule({imports: [OtherModule]})133 export class TestModule {}134 `);135 env.driveMain();136 const jsContents = env.getContents('test.js');137 expect(jsContents).toContain('i0.ɵɵdefineNgModule({ type: TestModule });');138 expect(jsContents)139 .toContain(140 'function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(TestModule, { imports: [OtherModule] }); })();');141 const dtsContents = env.getContents('test.d.ts');142 expect(dtsContents)143 .toContain(144 'static ɵmod: i0.ɵɵNgModuleDefWithMeta<TestModule, never, [typeof OtherModule], never>');145 });146 it('should produce an error when an invalid class is imported', () => {147 env.write('test.ts', `148 import {NgModule} from '@angular/core';149 class NotAModule {}150 @NgModule({imports: [NotAModule]})151 class IsAModule {}152 `);153 const [error] = env.driveDiagnostics();154 expect(error).not.toBeUndefined();155 expect(error.messageText).toContain('IsAModule');156 expect(error.messageText).toContain('NgModule.imports');157 expect(error.code).toEqual(ngErrorCode(ErrorCode.NGMODULE_INVALID_IMPORT));158 expect(diagnosticToNode(error, ts.isIdentifier).text).toEqual('NotAModule');159 });160 it('should produce an error when a non-class is imported from a .d.ts dependency', () => {161 env.write('dep.d.ts', `export declare let NotAClass: Function;`);162 env.write('test.ts', `163 import {NgModule} from '@angular/core';164 import {NotAClass} from './dep';165 @NgModule({imports: [NotAClass]})166 class IsAModule {}167 `);168 const [error] = env.driveDiagnostics();169 expect(error).not.toBeUndefined();170 expect(error.messageText).toContain('IsAModule');171 expect(error.messageText).toContain('NgModule.imports');172 expect(error.code).toEqual(ngErrorCode(ErrorCode.VALUE_HAS_WRONG_TYPE));173 expect(diagnosticToNode(error, ts.isIdentifier).text).toEqual('NotAClass');174 });175 });176 describe('exports', () => {177 it('should emit exports in a pure function call', () => {178 env.write('test.ts', `179 import {NgModule} from '@angular/core';180 @NgModule({})181 export class OtherModule {}182 @NgModule({exports: [OtherModule]})183 export class TestModule {}184 `);185 env.driveMain();186 const jsContents = env.getContents('test.js');187 expect(jsContents).toContain('i0.ɵɵdefineNgModule({ type: TestModule });');188 expect(jsContents)189 .toContain(190 '(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(TestModule, { exports: [OtherModule] }); })();');191 const dtsContents = env.getContents('test.d.ts');192 expect(dtsContents)193 .toContain(194 'static ɵmod: i0.ɵɵNgModuleDefWithMeta<TestModule, never, never, [typeof OtherModule]>');195 });196 it('should produce an error when a non-NgModule class is exported', () => {197 env.write('test.ts', `198 import {NgModule} from '@angular/core';199 class NotAModule {}200 @NgModule({exports: [NotAModule]})201 class IsAModule {}202 `);203 const [error] = env.driveDiagnostics();204 expect(error).not.toBeUndefined();205 expect(error.messageText).toContain('IsAModule');206 expect(error.messageText).toContain('NgModule.exports');207 expect(error.code).toEqual(ngErrorCode(ErrorCode.NGMODULE_INVALID_EXPORT));208 expect(diagnosticToNode(error, ts.isIdentifier).text).toEqual('NotAModule');209 });210 it('should produce a transitive error when an invalid NgModule is exported', () => {211 env.write('test.ts', `212 import {NgModule} from '@angular/core';213 export class NotAModule {}214 @NgModule({215 imports: [NotAModule],216 })217 class InvalidModule {}218 @NgModule({exports: [InvalidModule]})219 class IsAModule {}220 `);221 // Find the diagnostic referencing InvalidModule, which should have come from IsAModule.222 const error = env.driveDiagnostics().find(223 error => diagnosticToNode(error, ts.isIdentifier).text === 'InvalidModule');224 if (error === undefined) {225 return fail('Expected to find a diagnostic referencing InvalidModule');226 }227 expect(error.messageText).toContain('IsAModule');228 expect(error.messageText).toContain('NgModule.exports');229 expect(error.code).toEqual(ngErrorCode(ErrorCode.NGMODULE_INVALID_EXPORT));230 });231 });232 describe('re-exports', () => {233 it('should produce an error when a non-declared/imported class is re-exported', () => {234 env.write('test.ts', `235 import {Directive, NgModule} from '@angular/core';236 @Directive({selector: 'test'})237 class Dir {}238 @NgModule({exports: [Dir]})239 class IsAModule {}240 `);241 const [error] = env.driveDiagnostics();242 expect(error).not.toBeUndefined();243 expect(error.messageText).toContain('IsAModule');244 expect(error.messageText).toContain('NgModule.exports');245 expect(error.code).toEqual(ngErrorCode(ErrorCode.NGMODULE_INVALID_REEXPORT));246 expect(diagnosticToNode(error, ts.isIdentifier).text).toEqual('Dir');247 });248 });249 it('should not produce component template type-check errors if its module is invalid', () => {250 env.tsconfig({'fullTemplateTypeCheck': true});251 // Set up 3 files, each of which declare an NgModule that's invalid in some way. This will252 // produce a bunch of diagnostics related to the issues with the modules. Each module also253 // declares a component with a template that references a <doesnt-exist> element. This test254 // verifies that none of the produced diagnostics mention this nonexistent element, since255 // no template type-checking should be performed for a component that's part of an invalid256 // NgModule.257 // This NgModule declares something which isn't a directive/pipe.258 env.write('invalid-declaration.ts', `259 import {Component, NgModule} from '@angular/core';260 @Component({261 selector: 'test-cmp',262 template: '<doesnt-exist></doesnt-exist>',263 })264 export class TestCmp {}265 export class NotACmp {}266 @NgModule({declarations: [TestCmp, NotACmp]})267 export class Module {}268 `);269 // This NgModule imports something which isn't an NgModule.270 env.write('invalid-import.ts', `271 import {Component, NgModule} from '@angular/core';272 @Component({273 selector: 'test-cmp',274 template: '<doesnt-exist></doesnt-exist>',275 })276 export class TestCmp {}277 export class NotAModule {}278 @NgModule({279 declarations: [TestCmp],280 imports: [NotAModule],281 })282 export class Module {}283 `);284 // This NgModule imports a DepModule which itself is invalid (it declares something which285 // isn't a directive/pipe).286 env.write('transitive-error-in-import.ts', `287 import {Component, NgModule} from '@angular/core';288 @Component({289 selector: 'test-cmp',290 template: '<doesnt-exist></doesnt-exist>',291 })292 export class TestCmp {}293 export class NotACmp {}294 @NgModule({295 declarations: [NotACmp],296 exports: [NotACmp],297 })298 export class DepModule {}299 @NgModule({300 declarations: [TestCmp],301 imports: [DepModule],302 })303 export class Module {}304 `);305 for (const diag of env.driveDiagnostics()) {306 // None of the diagnostics should be related to the fact that the component uses an307 // unknown element, because in all cases the component's scope was invalid.308 expect(diag.messageText)309 .not.toContain(310 'doesnt-exist',311 'Template type-checking ran for a component, when it shouldn\'t have.');312 }313 });314 });315 });316 function diagnosticToNode<T extends ts.Node>(317 diagnostic: ts.Diagnostic | Diagnostic | ts.DiagnosticRelatedInformation,318 guard: (node: ts.Node) => node is T): T {319 const diag = diagnostic as ts.Diagnostic | ts.DiagnosticRelatedInformation;320 if (diag.file === undefined) {321 throw new Error(`Expected ts.Diagnostic to have a file source`);322 }323 const node = getTokenAtPosition(diag.file, diag.start !);324 expect(guard(node)).toBe(true);325 return node as T;326 }327});328function findContainingClass(node: ts.Node): ts.ClassDeclaration {329 while (!ts.isClassDeclaration(node)) {330 if (node.parent && node.parent !== node) {331 node = node.parent;332 } else {333 throw new Error('Expected node to have a ClassDeclaration parent');334 }335 }336 return node;...

Full Screen

Full Screen

ng_module.ts

Source:ng_module.ts Github

copy

Full Screen

1/**2 * @license3 * Copyright Google Inc. All Rights Reserved.4 *5 * Use of this source code is governed by an MIT-style license that can be6 * found in the LICENSE file at https://angular.io/license7 */8import {ApplicationRef} from '../application_ref';9import {InjectorType, ɵɵdefineInjector} from '../di/interface/defs';10import {Provider} from '../di/interface/provider';11import {convertInjectableProviderToFactory} from '../di/util';12import {Type} from '../interface/type';13import {SchemaMetadata} from '../metadata/schema';14import {compileNgModule as render3CompileNgModule} from '../render3/jit/module';15import {TypeDecorator, makeDecorator} from '../util/decorators';16/**17 * Represents the expansion of an `NgModule` into its scopes.18 *19 * A scope is a set of directives and pipes that are visible in a particular context. Each20 * `NgModule` has two scopes. The `compilation` scope is the set of directives and pipes that will21 * be recognized in the templates of components declared by the module. The `exported` scope is the22 * set of directives and pipes exported by a module (that is, module B's exported scope gets added23 * to module A's compilation scope when module A imports B).24 */25export interface NgModuleTransitiveScopes {26 compilation: {directives: Set<any>; pipes: Set<any>;};27 exported: {directives: Set<any>; pipes: Set<any>;};28 schemas: SchemaMetadata[]|null;29}30/**31 * @publicApi32 */33export type ɵɵNgModuleDefWithMeta<T, Declarations, Imports, Exports> = NgModuleDef<T>;34/**35 * Runtime link information for NgModules.36 *37 * This is the internal data structure used by the runtime to assemble components, directives,38 * pipes, and injectors.39 *40 * NOTE: Always use `ɵɵdefineNgModule` function to create this object,41 * never create the object directly since the shape of this object42 * can change between versions.43 */44export interface NgModuleDef<T> {45 /** Token representing the module. Used by DI. */46 type: T;47 /** List of components to bootstrap. */48 bootstrap: Type<any>[]|(() => Type<any>[]);49 /** List of components, directives, and pipes declared by this module. */50 declarations: Type<any>[]|(() => Type<any>[]);51 /** List of modules or `ModuleWithProviders` imported by this module. */52 imports: Type<any>[]|(() => Type<any>[]);53 /**54 * List of modules, `ModuleWithProviders`, components, directives, or pipes exported by this55 * module.56 */57 exports: Type<any>[]|(() => Type<any>[]);58 /**59 * Cached value of computed `transitiveCompileScopes` for this module.60 *61 * This should never be read directly, but accessed via `transitiveScopesFor`.62 */63 transitiveCompileScopes: NgModuleTransitiveScopes|null;64 /** The set of schemas that declare elements to be allowed in the NgModule. */65 schemas: SchemaMetadata[]|null;66 /** Unique ID for the module with which it should be registered. */67 id: string|null;68}69/**70 * A wrapper around an NgModule that associates it with the providers.71 *72 * @param T the module type. In Ivy applications, this must be explicitly73 * provided.74 *75 * Note that using ModuleWithProviders without a generic type is deprecated.76 * The generic will become required in a future version of Angular.77 *78 * @publicApi79 */80export interface ModuleWithProviders<81 T = any /** TODO(alxhub): remove default when callers pass explicit type param */> {82 ngModule: Type<T>;83 providers?: Provider[];84}85/**86 * Type of the NgModule decorator / constructor function.87 *88 * @publicApi89 */90export interface NgModuleDecorator {91 /**92 * Decorator that marks a class as an NgModule and supplies configuration metadata.93 */94 (obj?: NgModule): TypeDecorator;95 new (obj?: NgModule): NgModule;96}97/**98 * Type of the NgModule metadata.99 *100 * @publicApi101 */102export interface NgModule {103 /**104 * The set of injectable objects that are available in the injector105 * of this module.106 *107 * @see [Dependency Injection guide](guide/dependency-injection)108 * @see [NgModule guide](guide/providers)109 *110 * @usageNotes111 *112 * Dependencies whose providers are listed here become available for injection113 * into any component, directive, pipe or service that is a child of this injector.114 * The NgModule used for bootstrapping uses the root injector, and can provide dependencies115 * to any part of the app.116 *117 * A lazy-loaded module has its own injector, typically a child of the app root injector.118 * Lazy-loaded services are scoped to the lazy-loaded module's injector.119 * If a lazy-loaded module also provides the `UserService`, any component created120 * within that module's context (such as by router navigation) gets the local instance121 * of the service, not the instance in the root injector.122 * Components in external modules continue to receive the instance provided by their injectors.123 *124 * ### Example125 *126 * The following example defines a class that is injected in127 * the HelloWorld NgModule:128 *129 * ```130 * class Greeter {131 * greet(name:string) {132 * return 'Hello ' + name + '!';133 * }134 * }135 *136 * @NgModule({137 * providers: [138 * Greeter139 * ]140 * })141 * class HelloWorld {142 * greeter:Greeter;143 *144 * constructor(greeter:Greeter) {145 * this.greeter = greeter;146 * }147 * }148 * ```149 */150 providers?: Provider[];151 /**152 * The set of components, directives, and pipes ([declarables](guide/glossary#declarable))153 * that belong to this module.154 *155 * @usageNotes156 *157 * The set of selectors that are available to a template include those declared here, and158 * those that are exported from imported NgModules.159 *160 * Declarables must belong to exactly one module.161 * The compiler emits an error if you try to declare the same class in more than one module.162 * Be careful not to declare a class that is imported from another module.163 *164 * ### Example165 *166 * The following example allows the CommonModule to use the `NgFor`167 * directive.168 *169 * ```javascript170 * @NgModule({171 * declarations: [NgFor]172 * })173 * class CommonModule {174 * }175 * ```176 */177 declarations?: Array<Type<any>|any[]>;178 /**179 * The set of NgModules whose exported [declarables](guide/glossary#declarable)180 * are available to templates in this module.181 *182 * @usageNotes183 *184 * A template can use exported declarables from any185 * imported module, including those from modules that are imported indirectly186 * and re-exported.187 * For example, `ModuleA` imports `ModuleB`, and also exports188 * it, which makes the declarables from `ModuleB` available189 * wherever `ModuleA` is imported.190 *191 * ### Example192 *193 * The following example allows MainModule to use anything exported by194 * `CommonModule`:195 *196 * ```javascript197 * @NgModule({198 * imports: [CommonModule]199 * })200 * class MainModule {201 * }202 * ```203 *204 */205 imports?: Array<Type<any>|ModuleWithProviders<{}>|any[]>;206 /**207 * The set of components, directives, and pipes declared in this208 * NgModule that can be used in the template of any component that is part of an209 * NgModule that imports this NgModule. Exported declarations are the module's public API.210 *211 * A declarable belongs to one and only one NgModule.212 * A module can list another module among its exports, in which case all of that module's213 * public declaration are exported.214 *215 * @usageNotes216 *217 * Declarations are private by default.218 * If this ModuleA does not export UserComponent, then only the components within this219 * ModuleA can use UserComponent.220 *221 * ModuleA can import ModuleB and also export it, making exports from ModuleB222 * available to an NgModule that imports ModuleA.223 *224 * ### Example225 *226 * The following example exports the `NgFor` directive from CommonModule.227 *228 * ```javascript229 * @NgModule({230 * exports: [NgFor]231 * })232 * class CommonModule {233 * }234 * ```235 */236 exports?: Array<Type<any>|any[]>;237 /**238 * The set of components to compile when this NgModule is defined,239 * so that they can be dynamically loaded into the view.240 *241 * For each component listed here, Angular creates a `ComponentFactory`242 * and stores it in the `ComponentFactoryResolver`.243 *244 * Angular automatically adds components in the module's bootstrap245 * and route definitions into the `entryComponents` list. Use this246 * option to add components that are bootstrapped247 * using one of the imperative techniques, such as `ViewContainerRef.createComponent()`.248 *249 * @see [Entry Components](guide/entry-components)250 * @deprecated Since 9.0.0. With Ivy, this property is no longer necessary.251 */252 entryComponents?: Array<Type<any>|any[]>;253 /**254 * The set of components that are bootstrapped when255 * this module is bootstrapped. The components listed here256 * are automatically added to `entryComponents`.257 */258 bootstrap?: Array<Type<any>|any[]>;259 /**260 * The set of schemas that declare elements to be allowed in the NgModule.261 * Elements and properties that are neither Angular components nor directives262 * must be declared in a schema.263 *264 * Allowed value are `NO_ERRORS_SCHEMA` and `CUSTOM_ELEMENTS_SCHEMA`.265 *266 * @security When using one of `NO_ERRORS_SCHEMA` or `CUSTOM_ELEMENTS_SCHEMA`267 * you must ensure that allowed elements and properties securely escape inputs.268 */269 schemas?: Array<SchemaMetadata|any[]>;270 /**271 * A name or path that uniquely identifies this NgModule in `getModuleFactory`.272 * If left `undefined`, the NgModule is not registered with273 * `getModuleFactory`.274 */275 id?: string;276 /**277 * If true, this module will be skipped by the AOT compiler and so will always be compiled278 * using JIT.279 *280 * This exists to support future Ivy work and has no effect currently.281 */282 jit?: true;283}284/**285 * @Annotation286 * @publicApi287 */288export const NgModule: NgModuleDecorator = makeDecorator(289 'NgModule', (ngModule: NgModule) => ngModule, undefined, undefined,290 /**291 * Decorator that marks the following class as an NgModule, and supplies292 * configuration metadata for it.293 *294 * * The `declarations` and `entryComponents` options configure the compiler295 * with information about what belongs to the NgModule.296 * * The `providers` options configures the NgModule's injector to provide297 * dependencies the NgModule members.298 * * The `imports` and `exports` options bring in members from other modules, and make299 * this module's members available to others.300 */301 (type: Type<any>, meta: NgModule) => SWITCH_COMPILE_NGMODULE(type, meta));302/**303 * @description304 * Hook for manual bootstrapping of the application instead of using bootstrap array in @NgModule305 * annotation.306 *307 * Reference to the current application is provided as a parameter.308 *309 * See ["Bootstrapping"](guide/bootstrapping) and ["Entry components"](guide/entry-components).310 *311 * @usageNotes312 * ```typescript313 * class AppModule implements DoBootstrap {314 * ngDoBootstrap(appRef: ApplicationRef) {315 * appRef.bootstrap(AppComponent); // Or some other component316 * }317 * }318 * ```319 *320 * @publicApi321 */322export interface DoBootstrap { ngDoBootstrap(appRef: ApplicationRef): void; }323function preR3NgModuleCompile(moduleType: Type<any>, metadata?: NgModule): void {324 let imports = (metadata && metadata.imports) || [];325 if (metadata && metadata.exports) {326 imports = [...imports, metadata.exports];327 }328 (moduleType as InjectorType<any>).ɵinj = ɵɵdefineInjector({329 factory: convertInjectableProviderToFactory(moduleType, {useClass: moduleType}),330 providers: metadata && metadata.providers,331 imports: imports,332 });333}334export const SWITCH_COMPILE_NGMODULE__POST_R3__ = render3CompileNgModule;335const SWITCH_COMPILE_NGMODULE__PRE_R3__ = preR3NgModuleCompile;...

Full Screen

Full Screen

modulewithproviders_spec.ts

Source:modulewithproviders_spec.ts Github

copy

Full Screen

1/**2 * @license3 * Copyright Google Inc. All Rights Reserved.4 *5 * Use of this source code is governed by an MIT-style license that can be6 * found in the LICENSE file at https://angular.io/license7 */8import {runInEachFileSystem} from '../../src/ngtsc/file_system/testing';9import {loadStandardTestFiles} from '../helpers/src/mock_file_loading';10import {NgtscTestEnvironment} from './env';11const trim = (input: string): string => input.replace(/\s+/g, ' ').trim();12const testFiles = loadStandardTestFiles();13runInEachFileSystem(() => {14 describe('ModuleWithProviders generic type transform', () => {15 let env !: NgtscTestEnvironment;16 beforeEach(() => {17 env = NgtscTestEnvironment.setup(testFiles);18 env.tsconfig();19 });20 it('should add a generic type for static methods on exported classes', () => {21 env.write('test.ts', `22 import {NgModule} from '@angular/core';23 @NgModule()24 export class TestModule {25 static forRoot() {26 return {27 ngModule: TestModule,28 };29 }30 }31 `);32 env.driveMain();33 const dtsContents = trim(env.getContents('test.d.ts'));34 expect(dtsContents).toContain('import * as i0 from "@angular/core";');35 expect(dtsContents).toContain('static forRoot(): i0.ModuleWithProviders<TestModule>;');36 });37 it('should not add a generic type for non-static methods', () => {38 env.write('test.ts', `39 import {NgModule} from '@angular/core';40 @NgModule()41 export class TestModule {42 forRoot() {43 return {44 ngModule: TestModule,45 };46 }47 }48 `);49 env.driveMain();50 const dtsContents = trim(env.getContents('test.d.ts'));51 expect(dtsContents).toContain('import * as i0 from "@angular/core";');52 expect(dtsContents).toContain('forRoot(): { ngModule: typeof TestModule; };');53 expect(dtsContents).not.toContain('static forRoot()');54 });55 it('should add a generic type for exported functions', () => {56 env.write('test.ts', `57 import {NgModule} from '@angular/core';58 export function forRoot() {59 return {60 ngModule: TestModule,61 };62 }63 @NgModule()64 export class TestModule {}65 `);66 env.driveMain();67 const dtsContents = trim(env.getContents('test.d.ts'));68 expect(dtsContents).toContain('import * as i0 from "@angular/core";');69 expect(dtsContents)70 .toContain('export declare function forRoot(): i0.ModuleWithProviders<TestModule>;');71 });72 it('should not add a generic type when already present', () => {73 env.write('test.ts', `74 import {NgModule, ModuleWithProviders} from '@angular/core';75 export class TestModule {76 forRoot(): ModuleWithProviders<InternalTestModule> {77 return {78 ngModule: TestModule,79 };80 }81 }82 @NgModule()83 export class InternalTestModule {}84 `);85 env.driveMain();86 const dtsContents = trim(env.getContents('test.d.ts'));87 expect(dtsContents).toContain('forRoot(): ModuleWithProviders<InternalTestModule>;');88 });89 it('should add a generic type when missing the generic type parameter', () => {90 env.write('test.ts', `91 import {NgModule, ModuleWithProviders} from '@angular/core';92 @NgModule()93 export class TestModule {94 static forRoot(): ModuleWithProviders {95 return {96 ngModule: TestModule,97 };98 }99 }100 `);101 env.driveMain();102 const dtsContents = trim(env.getContents('test.d.ts'));103 expect(dtsContents).toContain('static forRoot(): i0.ModuleWithProviders<TestModule>;');104 });105 it('should add a generic type when missing the generic type parameter (qualified name)', () => {106 env.write('test.ts', `107 import * as ng from '@angular/core';108 @ng.NgModule()109 export class TestModule {110 static forRoot(): ng.ModuleWithProviders {111 return {112 ngModule: TestModule,113 };114 }115 }116 `);117 env.driveMain();118 const dtsContents = trim(env.getContents('test.d.ts'));119 expect(dtsContents).toContain('static forRoot(): i0.ModuleWithProviders<TestModule>;');120 });121 it('should add a generic type and add an import for external references', () => {122 env.write('test.ts', `123 import {ModuleWithProviders} from '@angular/core';124 import {InternalTestModule} from './internal';125 export class TestModule {126 static forRoot(): ModuleWithProviders {127 return {128 ngModule: InternalTestModule,129 };130 }131 }132 `);133 env.write('internal.ts', `134 import {NgModule} from '@angular/core';135 @NgModule()136 export class InternalTestModule {}137 `);138 env.driveMain();139 const dtsContents = trim(env.getContents('test.d.ts'));140 expect(dtsContents).toContain('import * as i1 from "./internal";');141 expect(dtsContents)142 .toContain('static forRoot(): i0.ModuleWithProviders<i1.InternalTestModule>;');143 });144 it('should not add a generic type if the return type is not ModuleWithProviders', () => {145 env.write('test.ts', `146 import {NgModule} from '@angular/core';147 @NgModule()148 export class TestModule {149 static forRoot(): { ngModule: typeof TestModule } {150 return {151 ngModule: TestModule,152 };153 }154 }155 `);156 env.driveMain();157 const dtsContents = trim(env.getContents('test.d.ts'));158 expect(dtsContents).toContain('static forRoot(): { ngModule: typeof TestModule; };');159 });160 it('should not add a generic type if the return type is not ModuleWithProviders from @angular/core',161 () => {162 env.write('test.ts', `163 import {NgModule} from '@angular/core';164 import {ModuleWithProviders} from './mwp';165 @NgModule()166 export class TestModule {167 static forRoot(): ModuleWithProviders {168 return {169 ngModule: TestModule,170 };171 }172 }173 `);174 env.write('mwp.ts', `175 export type ModuleWithProviders = { ngModule: any };176 `);177 env.driveMain();178 const dtsContents = trim(env.getContents('test.d.ts'));179 expect(dtsContents).toContain('static forRoot(): ModuleWithProviders;');180 });181 it('should not add a generic type when the "ngModule" property is not a reference', () => {182 env.write('test.ts', `183 import {NgModule} from '@angular/core';184 @NgModule()185 export class TestModule {186 static forRoot() {187 return {188 ngModule: 'test',189 };190 }191 }192 `);193 env.driveMain();194 const dtsContents = trim(env.getContents('test.d.ts'));195 expect(dtsContents).toContain('static forRoot(): { ngModule: string; };');196 });197 it('should not add a generic type when the class is not exported', () => {198 env.write('test.ts', `199 import {NgModule} from '@angular/core';200 @NgModule()201 class TestModule {202 static forRoot() {203 return {204 ngModule: TestModule,205 };206 }207 }208 `);209 env.driveMain();210 // The TestModule class is not exported so doesn't even show up in the declaration file211 const dtsContents = trim(env.getContents('test.d.ts'));212 expect(dtsContents).not.toContain('static forRoot()');213 });214 it('should add a generic type only when ngModule/providers are present', () => {215 env.write('test.ts', `216 import {NgModule, ModuleWithProviders} from '@angular/core';217 @NgModule()218 export class TestModule {219 static hasNgModuleAndProviders() {220 return {221 ngModule: TestModule,222 providers: [],223 };224 }225 static hasNgModuleAndFoo() {226 return {227 ngModule: TestModule,228 foo: 'test',229 };230 }231 }232 `);233 env.driveMain();234 const dtsContents = trim(env.getContents('test.d.ts'));235 expect(dtsContents)236 .toContain('static hasNgModuleAndProviders(): i0.ModuleWithProviders<TestModule>;');237 expect(dtsContents)238 .toContain('static hasNgModuleAndFoo(): { ngModule: typeof TestModule; foo: string; };');239 });240 });...

Full Screen

Full Screen

config.ts

Source:config.ts Github

copy

Full Screen

1//@ts-ignore2import * as mantenimientoCorrModule from 'mp-forest-mantenimiento-correspondencia';3//Workplace45//@ts-ignore6@NgModule({7 declarations: [],8 imports: [9 //@ts-ignore10 CommonModule,11 mantenimientoCorrModule.CUMCO001Module12 ]13})14export class ICUMCO001Module { }1516//@ts-ignore17@NgModule({18 declarations: [],19 imports: [20 //@ts-ignore21 CommonModule,22 mantenimientoCorrModule.Cumco003Module23 ]24})25export class ICumco003Module { }262728//@ts-ignore29@NgModule({30 declarations: [],31 imports: [32 //@ts-ignore33 CommonModule,34 mantenimientoCorrModule.CUMCO004Module 35 ]36})37export class ICUMCO004Module { }383940//@ts-ignore41@NgModule({42 declarations: [],43 imports: [44 //@ts-ignore45 CommonModule,46 mantenimientoCorrModule.Cumco005Module47 ]48})49export class ICumco005Module { }5051//@ts-ignore52@NgModule({53 declarations: [],54 imports: [55 //@ts-ignore56 CommonModule,57 mantenimientoCorrModule.Cumco006Module58 ]59})60export class ICumco006Module { }6162//@ts-ignore63@NgModule({64 declarations: [],65 imports: [66 //@ts-ignore67 CommonModule,68 mantenimientoCorrModule.Cumco008Module69 ]70})71export class ICumco008Module { }7273//@ts-ignore74@NgModule({75 declarations: [],76 imports: [77 //@ts-ignore78 CommonModule,79 mantenimientoCorrModule.CUMCO009Module80 ]81})82export class ICUMCO009Module { }8384//@ts-ignore85@NgModule({86 declarations: [],87 imports: [88 //@ts-ignore89 CommonModule,90 mantenimientoCorrModule.CUMCO010Module91 ]92})93export class ICUMCO010Module { }9495//@ts-ignore96@NgModule({97 declarations: [],98 imports: [99 //@ts-ignore100 CommonModule,101 mantenimientoCorrModule.CUMCO012Module102 ]103})104export class ICUMCO012Module { }105106//@ts-ignore107@NgModule({108 declarations: [],109 imports: [110 //@ts-ignore111 CommonModule,112 mantenimientoCorrModule.CUMCO014Module113 ]114})115export class ICUMCO014Module { }116117//@ts-ignore118@NgModule({119 declarations: [],120 imports: [121 //@ts-ignore122 CommonModule,123 mantenimientoCorrModule.CUMCO013Module124 ]125})126export class ICUMCO013Module { }127128//@ts-ignore129@NgModule({130 declarations: [],131 imports: [132 //@ts-ignore133 CommonModule,134 mantenimientoCorrModule.Cumco016Module135 ]136})137export class ICumco016Module { }138139//@ts-ignore140@NgModule({141 declarations: [],142 imports: [143 //@ts-ignore144 CommonModule,145 mantenimientoCorrModule.Cumco017Module146 ]147})148export class ICumco017Module { }149150151//@ts-ignore152@NgModule({153 declarations: [],154 imports: [155 //@ts-ignore156 CommonModule,157 mantenimientoCorrModule.CUMCO018Module158 ]159})160export class ICUMCO018Module { }161162//@ts-ignore163@NgModule({164 declarations: [],165 imports: [166 //@ts-ignore167 CommonModule,168 mantenimientoCorrModule.CUMCO019Module169 ]170})171export class ICUMCO019Module { }172173//@ts-ignore174@NgModule({175 declarations: [],176 imports: [177 //@ts-ignore178 CommonModule,179 mantenimientoCorrModule.Cumco020Module180 ]181})182export class ICumco020Module { }183 ...

Full Screen

Full Screen

verdaccio-config.module.ts

Source:verdaccio-config.module.ts Github

copy

Full Screen

1import { NgModule } from '@angular/core';2import { CommonModule } from '@angular/common';3//#modulosVerdacio4//@ts-ignore5import * as mantenimientoCorrModule from 'mp-forest-mantenimiento-correspondencia';6//Workplace7//@ts-ignore8@NgModule({9 declarations: [],10 imports: [11 //@ts-ignore12 CommonModule,13 mantenimientoCorrModule.CUMCO001Module14 ]15})16export class ICUMCO001Module { }17//@ts-ignore18@NgModule({19 declarations: [],20 imports: [21 //@ts-ignore22 CommonModule,23 mantenimientoCorrModule.Cumco003Module24 ]25})26export class ICumco003Module { }27//@ts-ignore28@NgModule({29 declarations: [],30 imports: [31 //@ts-ignore32 CommonModule,33 mantenimientoCorrModule.CUMCO004Module34 ]35})36export class ICUMCO004Module { }37//@ts-ignore38@NgModule({39 declarations: [],40 imports: [41 //@ts-ignore42 CommonModule,43 mantenimientoCorrModule.Cumco005Module44 ]45})46export class ICumco005Module { }47//@ts-ignore48@NgModule({49 declarations: [],50 imports: [51 //@ts-ignore52 CommonModule,53 mantenimientoCorrModule.Cumco006Module54 ]55})56export class ICumco006Module { }57//@ts-ignore58@NgModule({59 declarations: [],60 imports: [61 //@ts-ignore62 CommonModule,63 mantenimientoCorrModule.Cumco008Module64 ]65})66export class ICumco008Module { }67//@ts-ignore68@NgModule({69 declarations: [],70 imports: [71 //@ts-ignore72 CommonModule,73 mantenimientoCorrModule.CUMCO009Module74 ]75})76export class ICUMCO009Module { }77//@ts-ignore78@NgModule({79 declarations: [],80 imports: [81 //@ts-ignore82 CommonModule,83 mantenimientoCorrModule.CUMCO010Module84 ]85})86export class ICUMCO010Module { }87//@ts-ignore88@NgModule({89 declarations: [],90 imports: [91 //@ts-ignore92 CommonModule,93 mantenimientoCorrModule.CUMCO012Module94 ]95})96export class ICUMCO012Module { }97//@ts-ignore98@NgModule({99 declarations: [],100 imports: [101 //@ts-ignore102 CommonModule,103 mantenimientoCorrModule.CUMCO014Module104 ]105})106export class ICUMCO014Module { }107//@ts-ignore108@NgModule({109 declarations: [],110 imports: [111 //@ts-ignore112 CommonModule,113 mantenimientoCorrModule.CUMCO013Module114 ]115})116export class ICUMCO013Module { }117//@ts-ignore118@NgModule({119 declarations: [],120 imports: [121 //@ts-ignore122 CommonModule,123 mantenimientoCorrModule.Cumco016Module124 ]125})126export class ICumco016Module { }127//@ts-ignore128@NgModule({129 declarations: [],130 imports: [131 //@ts-ignore132 CommonModule,133 mantenimientoCorrModule.Cumco017Module134 ]135})136export class ICumco017Module { }137//@ts-ignore138@NgModule({139 declarations: [],140 imports: [141 //@ts-ignore142 CommonModule,143 mantenimientoCorrModule.CUMCO018Module144 ]145})146export class ICUMCO018Module { }147//@ts-ignore148@NgModule({149 declarations: [],150 imports: [151 //@ts-ignore152 CommonModule,153 mantenimientoCorrModule.CUMCO019Module154 ]155})156export class ICUMCO019Module { }157//@ts-ignore158@NgModule({159 declarations: [],160 imports: [161 //@ts-ignore162 CommonModule,163 mantenimientoCorrModule.Cumco020Module164 ]165})...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { NgModule } from '@angular/core';2import { BrowserModule } from '@angular/platform-browser';3import { FormsModule } from '@angular/forms';4import { AppComponent } from './app.component';5import { HelloComponent } from './hello.component';6@NgModule({7 imports: [ BrowserModule, FormsModule ],8})9export class AppModule { }10import { Component } from '@angular/core';11@Component({12 h1 {13 font-family: Lato;14 }15})16export class AppComponent { name = 'Angular'; }17import { Component } from '@angular/core';18@Component({19 template: `<h1>Hello {{name}}</h1>`,20 h1 {21 font-family: Lato;22 }23})24export class HelloComponent { name = 'Angular'; }

Full Screen

Using AI Code Generation

copy

Full Screen

1import { NgModule } from '@angular/core';2import { BrowserModule } from '@angular/platform-browser';3import { ButtonComponent } from './button.component';4import { ButtonModule } from './button.module';5@NgModule({6 imports: [BrowserModule, ButtonModule],7})8export class ButtonRootModule {}9import { Component } from '@angular/core';10import { ButtonComponent } from './button.component';11import { ButtonModule } from './button.module';12@Component({13})14export class ButtonRootComponent {15 label = 'Hello Button';16 type = 'primary';17}18import { NgModule } from '@angular/core';19import { ButtonComponent } from './button.component';20@NgModule({21 imports: [],22})23export class ButtonModule {}24import { Component, Input } from '@angular/core';25@Component({26})27export class ButtonComponent {28 @Input() label = 'Button';29 @Input() type = 'primary';30}31<button type="button" class="btn btn-{{ type }}">{{ label }}</button>32.btn {33 font-size: 14px;34 font-weight: 500;35 padding: 0.375rem 0.75rem;36 border-radius: 0.25rem;37 border: 1px solid transparent;38 text-transform: uppercase;39}40.btn-primary {41 color: #fff;42 background-color: #007bff;43 border-color: #007bff;44}45.btn-secondary {46 color: #fff;47 background-color: #6c757d;48 border-color: #6c757d;49}50.btn-success {51 color: #fff;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { BrowserModule } from '@angular/platform-browser';2import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';3import { AppComponent } from './app.component';4import { StorybookModule } from 'storybook-root';5@NgModule({6 imports: [7})8export class AppModule { }9import { Component, OnInit } from '@angular/core';10import { StorybookService } from 'storybook-root';11@Component({12})13export class AppComponent implements OnInit {14 title = 'storybook-root';15 constructor(public storybookService: StorybookService) {16 }17 ngOnInit() {18 this.storybookService.loadStories();19 }20}21storybook-root {22 display: block;23 width: 100%;24 height: 100%;25}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ngModule } from 'storybook-root';2import { ngModule } from 'storybook-root';3import { ngModule } from 'storybook-root';4import { ngModule } from 'storybook-root';5import { ngModule } from 'storybook-root';6import { ngModule } from 'storybook-root';7import { ngModule } from 'storybook-root';8import { ngModule } from 'storybook-root';9import { ngModule } from 'storybook-root';10import { ngModule } from 'storybook-root';11import { ngModule } from 'storybook-root';12import { ngModule } from 'storybook-root';13import { ngModule } from 'storybook-root';14import { ngModule } from 'storybook-root';15import { ngModule } from 'storybook-root';16import { ngModule } from 'storybook-root';17import { ngModule } from 'storybook-root';18import { ngModule } from 'storybook-root';19import { ngModule } from 'storybook-root';20import { ngModule } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import {ngModule} from 'storybook-root';2import {MyModule} from './my-module';3ngModule(MyModule);4import {ngModule} from 'storybook-root';5import {NgModule} from '@angular/core';6import {MyComponent} from './my-component';7@NgModule({8})9export class MyModule {10}11ngModule(MyModule);12import {ngModule} from 'storybook-root';13import {Component} from '@angular/core';14@Component({15})16export class MyComponent {17}18ngModule(MyComponent);19import {storiesOf} from '@storybook/angular';20import {MyComponent} from './my-component';21storiesOf('MyComponent', module)22 .add('default', () => ({23 }));

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ngModule } from 'storybook-root';2import { MyComponent } from './my-component';3import { MyService } from './my-service';4export default ngModule({5 imports: [MyService],6});7import { MyComponent } from './my-component';8import { MyService } from './my-service';9describe('MyComponent', () => {10 it('should render', () => {11 const myService = new MyService();12 const myComponent = new MyComponent(myService);13 expect(myComponent.render()).toEqual('Hello World');14 });15});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ngModule } from './storybook-root.module';2import { NgxUiLoaderModule } from 'ngx-ui-loader';3export default {4 moduleMetadata({5 imports: [ngModule, NgxUiLoaderModule],6 }),7};8import { NgModule } from '@angular/core';9import { CommonModule } from '@angular/common';10import { BrowserAnimationsModule } from '@angular/platform-browser/animations';11import { ToastrModule } from 'ngx-toastr';12@NgModule({13 imports: [CommonModule, BrowserAnimationsModule, ToastrModule.forRoot()],14})15export class StorybookRootModule {}16import { BrowserModule } from '@angular/platform-browser';17import { BrowserAnimationsModule } from '@angular/platform-browser/animations';18import { ToastrModule } from 'ngx-toastr';19export default {20 moduleMetadata({21 imports: [BrowserModule, BrowserAnimationsModule, ToastrModule.forRoot()],22 }),23};

Full Screen

Using AI Code Generation

copy

Full Screen

1import {ngModule} from 'storybook-root';2ngModule.module('test', [])3 .component('test', {4 });5import {ngModule} from 'storybook-root';6describe('test', function() {7 beforeEach(angular.mock.module('test'));8 it('should pass', function() {9 });10});11import {storiesOf} from 'storybook-root';12storiesOf('test', module)13 .add('test', function() {14 return {15 };16 });17MIT © [Sriram](

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ngModule } from 'storybook-root';2import { module } from 'angular';3ngModule(module('moduleName',[]));4import { ngModule } from 'storybook-root';5import { module } from 'angular';6ngModule(module('moduleName',[]));7import { ngModule } from 'storybook-root';8import { module } from 'angular';9ngModule(module('moduleName',[]));10import { ngModule } from 'storybook-root';11import { module } from 'angular';12ngModule(module('moduleName',[]));13import { ngModule } from 'storybook-root';14import { module } from 'angular';15ngModule(module('moduleName',[]));16import { ngModule } from 'storybook-root';17import { module } from 'angular';18ngModule(module('moduleName',[]));19import { ngModule } from 'storybook-root';20import { module } from 'angular';21ngModule(module('moduleName',[]));22import { ngModule } from 'storybook-root';23import { module } from 'angular';24ngModule(module('moduleName',[]));25import { ngModule } from 'storybook-root';26import { module } from 'angular';27ngModule(module('moduleName',[]));28import { ngModule } from 'storybook-root';29import { module } from 'angular

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful