Open Closed

Angular Testing; DynamicTestModule error. #7022


User avatar
0
gogu.stere@3sstudio.com created
  • ABP Framework version: v8.0.4

  • UI Type: Angular

  • Database System: EF Core

  • Exception message and full stack trace:

    • Error: Unexpected value 'undefined' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation. at verifySemanticsOfNgModuleDef (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:28929:19) at forEach (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:28940:9) at Array.forEach (<anonymous>) at verifySemanticsOfNgModuleDef (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:28938:60) at Function.get (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/core.mjs:28891:30) at TestBedCompiler.applyProviderOverridesInScope (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/testing.mjs:1110:33) at TestBedCompiler.compileTestModule (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/testing.mjs:1405:14) at TestBedCompiler.finalize (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/testing.mjs:935:14) at TestBedImpl.testModuleRef (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/testing.mjs:1932:49) at TestBedImpl.inject (http://localhost:9876/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2022/testing.mjs:1842:29)

    • TypeError: Cannot read properties of undefined (reading 'componentInstance') at UserContext.apply (http://localhost:9876/_karma_webpack_/webpack:/src/app/rule/rule-definition-management/rule-definition-management.component.spec.ts:94:13) at _ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone.js:368:26) at ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:273:39) at _ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone.js:367:52) at Zone.run (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone.js:129:43) at runInTestZone (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:555:34) at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:570:20) at <Jasmine>

  • Steps to reproduce the issue: That's my test configuration: `beforeEach( waitForAsync(() => { TestBed.configureTestingModule({ declarations: [RuleDefinitionManagementComponent], imports: [ CoreTestingModule.withConfig(), ThemeSharedTestingModule.withConfig(), RuleModule, NgxValidateCoreModule, VALIDATION_BLUEPRINTS ], providers: [] }).compileComponents(); }) );

    beforeEach(() => { fixture = TestBed.createComponent(RuleDefinitionManagementComponent); fixture.detectChanges(); });

    it("should be initiated", () => { // expect(fixture.componentInstance.ruleDefinitionToDisplay).toEqual(ruleDefinitionMock); expect(fixture.componentInstance).toBeTruthy(); });`

RuleModule includes @NgModule for Rules.

That are my injections in TS class: private ruleService = inject(RuleService); private ruleDataModelService = inject(RuleDataModelService); private ruleDefinitionService = inject(RuleDefinitionService); private ruleUtils = inject(RuleUtils); private generalUtils = inject(GeneralUtils); private formBuilder = inject(FormBuilder); private toast = inject(ToasterService); private router = inject(Router); private localizationService = inject(LocalizationService); private confirmation = inject(ConfirmationService); private constants = inject(Constants); private location = inject(Location);


2 Answer(s)
  • User Avatar
    0
    yusuf.cirak created
    Support Team Angular Developer

    Hi,

    I wasn't able to reproduce your problem but i've imported CoreTestingModule, ThemeSharedTestingModule, NgxValidateCoreModule, VALIDATION_BLUEPRINTS and got some errors from CoreTestingModule.

    I've updated my CoreTestingModule and the tests run without problem. I think you should check this PR : https://github.com/abpframework/abp/pull/19571

    You're only testing the initialization of your component but i think this will be worth reading after we solve this issue.

    LocalizationService has it's own dependencies so it's hard to mock it's requirements, mocking LocalizationService itself might help which what we did in this PR: https://github.com/abpframework/abp/pull/19478.

    Please let me know if you still have errors after applying these solutions

  • User Avatar
    0
    gogu.stere@3sstudio.com created

    Thanks for response. I managed to fix the errors.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11