- ABP Framework version: v7.0.3
- UI type: Angular
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): yes / no
- My test code:
import { CoreTestingModule } from '@abp/ng.core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { VendorPurchasesComponent } from './vendor-purchases.component';
describe('VendorPurchasesComponent', () => { let component: VendorPurchasesComponent; let fixture: ComponentFixture<VendorPurchasesComponent>;
beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [VendorPurchasesComponent], imports: [CoreTestingModule.withConfig()] }).compileComponents(); });
beforeEach(() => { fixture = TestBed.createComponent(VendorPurchasesComponent); component = fixture.componentInstance; fixture.detectChanges(); });
it('should create', () => { expect(component).toBeTruthy(); }); });
- Exception message and stack trace: NullInjectorError: R3InjectorError(DynamicTestModule)[InjectionToken Provides currency symbol based for selected locale -> ConfigStateService -> InjectionToken INCUDE_LOCALIZATION_RESOURCES_TOKEN -> InjectionToken INCUDE_LOCALIZATION_RESOURCES_TOKEN]: NullInjectorError: No provider for InjectionToken INCUDE_LOCALIZATION_RESOURCES_TOKEN! error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'InjectionToken Provides currency symbol based for selected locale', 'ConfigStateService', 'InjectionToken INCUDE_LOCALIZATION_RESOURCES_TOKEN', 'InjectionToken INCUDE_LOCALIZATION_RESOURCES_TOKEN' ] }) at NullInjector.get (node_modules/@angular/core/fesm2020/core.mjs:7546:27) at R3Injector.get (node_modules/@angular/core/fesm2020/core.mjs:7967:33) at R3Injector.get (node_modules/@angular/core/fesm2020/core.mjs:7967:33) at injectInjectorOnly (node_modules/@angular/core/fesm2020/core.mjs:633:33) at Module.ɵɵinject (node_modules/@angular/core/fesm2020/core.mjs:637:60) at Object.factory (node_modules/@abp/ng.core/fesm2020/abp-ng.core.mjs:57:110) at R3Injector.hydrate (node_modules/@angular/core/fesm2020/core.mjs:8068:35) at R3Injector.get (node_modules/@angular/core/fesm2020/core.mjs:7956:33) at injectInjectorOnly (node_modules/@angular/core/fesm2020/core.mjs:633:33) at ɵɵinject (node_modules/@angular/core/fesm2020/core.mjs:637:60)
If I add providers:
import { INCUDE_LOCALIZATION_RESOURCES_TOKEN, LocalizationService } from '@abp/ng.core'; import { CoreTestingModule } from '@abp/ng.core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { VendorPurchasesComponent } from './vendor-purchases.component';
describe('VendorPurchasesComponent', () => { let component: VendorPurchasesComponent; let fixture: ComponentFixture<VendorPurchasesComponent>;
beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [VendorPurchasesComponent], imports: [CoreTestingModule.withConfig()], providers: [ LocalizationService, { provide: INCUDE_LOCALIZATION_RESOURCES_TOKEN, useValue: false }] }).compileComponents(); });
beforeEach(() => { fixture = TestBed.createComponent(VendorPurchasesComponent); component = fixture.componentInstance; fixture.detectChanges(); });
it('should create', () => { expect(component).toBeTruthy(); }); });
I still get error from LocalizationService instant method:
TypeError: Cannot read properties of undefined (reading 'instant') at new VendorPurchasesComponent (projects/SCM.Analytics/projects/analytics/src/lib/vendor/components/vendor-purchases/vendor-purchases.component.ts:21:54) at NodeInjectorFactory.factory (ng:///VendorPurchasesComponent/ɵfac.js:4:10) at getNodeInjectable (node_modules/@angular/core/fesm2020/core.mjs:3436:44) at createRootComponent (node_modules/@angular/core/fesm2020/core.mjs:12289:35) at ComponentFactory.create (node_modules/@angular/core/fesm2020/core.mjs:12170:25) at apply (node_modules/@angular/core/fesm2020/testing.mjs:24238:51) at _ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:412:30) at ProxyZoneSpec.onInvoke (node_modules/zone.js/fesm2015/zone-testing.js:287:39) at _ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:411:56) at Object.onInvoke (node_modules/@angular/core/fesm2020/core.mjs:24178:33)
6 Answer(s)
-
0
We must update Core/testing packages,I have noted.You are not required to wait for the publication of this issue. add missing provider on your test suite like
INCUDE_LOCALIZATION_RESOURCES_TOKEN
then it will be worked.here the issue link. https://github.com/abpframework/abp/issues/15991
-
0
When I provide that token, there still problem with LocalizationService instant method throwing exception:
TypeError: Cannot read properties of undefined (reading 'instant') at new VendorPurchasesComponent (projects/SCM.Analytics/projects/analytics/src/lib/vendor/components/vendor-purchases/vendor-purchases.component.ts:21:54) at NodeInjectorFactory.factory (ng:///VendorPurchasesComponent/ɵfac.js:4:10) at getNodeInjectable (node_modules/@angular/core/fesm2020/core.mjs:3436:44) at createRootComponent (node_modules/@angular/core/fesm2020/core.mjs:12289:35) at ComponentFactory.create (node_modules/@angular/core/fesm2020/core.mjs:12170:25) at apply (node_modules/@angular/core/fesm2020/testing.mjs:24238:51) at _ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:412:30) at ProxyZoneSpec.onInvoke (node_modules/zone.js/fesm2015/zone-testing.js:287:39) at _ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:411:56) at Object.onInvoke (node_modules/@angular/core/fesm2020/core.mjs:24178:33)
Providing mock version of LocalizationService does not fix this which is odd.
-
0
When I provide that token, there still problem with LocalizationService instant method throwing exception:
TypeError: Cannot read properties of undefined (reading 'instant') at new VendorPurchasesComponent (projects/SCM.Analytics/projects/analytics/src/lib/vendor/components/vendor-purchases/vendor-purchases.component.ts:21:54) at NodeInjectorFactory.factory (ng:///VendorPurchasesComponent/ɵfac.js:4:10) at getNodeInjectable (node_modules/@angular/core/fesm2020/core.mjs:3436:44) at createRootComponent (node_modules/@angular/core/fesm2020/core.mjs:12289:35) at ComponentFactory.create (node_modules/@angular/core/fesm2020/core.mjs:12170:25) at apply (node_modules/@angular/core/fesm2020/testing.mjs:24238:51) at _ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:412:30) at ProxyZoneSpec.onInvoke (node_modules/zone.js/fesm2015/zone-testing.js:287:39) at _ZoneDelegate.invoke (node_modules/zone.js/dist/zone.js:411:56) at Object.onInvoke (node_modules/@angular/core/fesm2020/core.mjs:24178:33)
Providing mock version of LocalizationService does not fix this which is odd.
Localization service does not have to provide. it already mark as 'provide-in:root' I have created a example. it works for me. I have tested like that. It works. https://gist.github.com/mahmut-gundogdu/470ac9adb005f9521efc13122bcef8da Could you check my example? And try again. I couldn't produce yet. Localization service doesn't use that token. ConfigStateService use that.
-
0
Yes that code works on our main angular application but not in library projects. Not sure why.
There was another NullInjectorError I ran into: NullInjectorError: R3InjectorError(DynamicTestModule)[InjectionToken QUEUE_MANAGER -> InjectionToken QUEUE_MANAGER]: NullInjectorError: No provider for InjectionToken QUEUE_MANAGER! error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'InjectionToken QUEUE_MANAGER', 'InjectionToken QUEUE_MANAGER' ] }) NullInjectorError: R3InjectorError(DynamicTestModule)[InjectionToken QUEUE_MANAGER -> InjectionToken QUEUE_MANAGER]: NullInjectorError: No provider for InjectionToken QUEUE_MANAGER! at NullInjector.get (node_modules/@angular/core/fesm2020/core.mjs:7498:27) at R3Injector.get (node_modules/@angular/core/fesm2020/core.mjs:7919:33) at R3Injector.get (node_modules/@angular/core/fesm2020/core.mjs:7919:33) at ChainedInjector.get (node_modules/@angular/core/fesm2020/core.mjs:12077:36) at lookupTokenUsingModuleInjector (node_modules/@angular/core/fesm2020/core.mjs:3206:39) at getOrCreateInjectable (node_modules/@angular/core/fesm2020/core.mjs:3251:12) at Module.ɵɵdirectiveInject (node_modules/@angular/core/fesm2020/core.mjs:10034:12) at NodeInjectorFactory.factory (node_modules/@abp/ng.core/fesm2020/abp-ng.core.mjs:57:110) at getNodeInjectable (node_modules/@angular/core/fesm2020/core.mjs:3436:44) at instantiateAllDirectives (node_modules/@angular/core/fesm2020/core.mjs:10990:27)
Similarly I could fix this by providing "QUEUE_MANAGER" in test.
-
0
Seems that problem was related if class property was initialized with localized value. Moving instant method usage in constructor fixed this issue.
-
0
Seems that problem was related if class property was initialized with localized value. Moving instant method usage in constructor fixed this issue.
A interesting problem. I thank you for responding. The missing providers have also been added. It will be published in the next 7.0 patch. The issue was fixed. If your problem persists, please reopen it.