In an Angular 13 project using ngx-cookieconsent, mocks can be used in tests.
Actual Behaviour
In an Angular 13 project, mocking a provider from a module that includes ngx-cookieconsent causes an error:
Importing NgcCookieConsentModule which does not have a ɵmod property
at ../../../../../packages/core/src/di/reflective_errors.ts:59:2
at Array.forEach (<anonymous>)
at transitiveScopesFor (../../../../../packages/core/src/di/reflective_errors.ts:56:9)
at ../../../../../packages/core/src/di/reflective_errors.ts:62:23
at Array.forEach (<anonymous>)
at transitiveScopesFor (../../../../../packages/core/src/di/reflective_errors.ts:56:9)
at setScopeOnDeclaredComponents (../../../node_modules/@angular/core/fesm2020/core.mjs:13514:28)
at flushModuleScopingQueueAsMuchAsPossible (../../../node_modules/@angular/core/fesm2020/core.mjs:13267:11)
at TestBedRender3.checkGlobalCompilationFinished (../../../node_modules/@angular/core/fesm2015/testing.mjs:1349:69)
at TestBedRender3.configureTestingModule (../../../../../packages/core/testing/src/r3_test_bed_compiler.ts:625:4)
at Function.delete (../../../node_modules/@angular/core/fesm2015/testing.mjs:1165:26)
at Function.<anonymous> (../../../node_modules/ng-mocks/webpack:/ng-mocks/libs/ng-mocks/src/lib/common/ng-mocks-global-overrides.ts:208:28)
at Function.i.TestBed.ngMocksFasterInstalled.i.TestBed.configureTestingModule (../../../node_modules/ng-mocks/index.js:1:145624)
at ../../../node_modules/@ngneat/spectator/fesm2020/ngneat-spectator.mjs:1170:28
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:407:30)
at AsyncTestZoneSpec.Object.<anonymous>.AsyncTestZoneSpec.onInvoke (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:4712:47)
at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:3762:43)
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:406:56)
at Zone.Object.<anonymous>.Zone.runGuarded (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:178:51)
at runInTestZone (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:4833:33)
at ../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:4784:21
at new ZoneAwarePromise (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:1347:33)
at ../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:4783:24
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:407:30)
at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:3765:43)
at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:406:56)
at Zone.Object.<anonymous>.Zone.run (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:167:47)
at Object.wrappedFunc (../../../node_modules/zone.js/bundles/zone-testing-bundle.umd.js:4250:34)
Steps to reproduce the behaviour
Create Angular 13 project.
Import ngx-cookieconsent in the app module
Create a spec with a mockProvider call like this:
import { ZipCodeService } from 'xxx/shared';
import { createServiceFactory, mockProvider } from '@ngneat/spectator/jest';
import { NEVER } from 'rxjs';
import { ZipCodeAsyncValidator } from './zip-code-validator';
describe('ZipCodeAsyncValidator', () => {
let service: ZipCodeAsyncValidator;
const createService = createServiceFactory({
service: ZipCodeAsyncValidator,
providers: [
mockProvider(ZipCodeService, { isValid: jest.fn(() => NEVER) }),
],
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
(note: ZipCodeService in this case does not contain anything meaningful or any further imports.)
Run the spec
Observe the following error: Error: Importing NgcCookieConsentModule which does not have a ɵmod property
Doing the same steps in an Angular 12 project works fine.
Ngx-CookieConsent Version
v2.2.3
CookieConsent Version
v3.1.1
Angular CLI (or Nx CLI) Version
v13.9.4
Node Version
v16.14.2
OS Version
Tested on Windows, Mac OS
Expected Behaviour
In an Angular 13 project using ngx-cookieconsent, mocks can be used in tests.
Actual Behaviour
In an Angular 13 project, mocking a provider from a module that includes ngx-cookieconsent causes an error:
Steps to reproduce the behaviour
(note: ZipCodeService in this case does not contain anything meaningful or any further imports.)
Error: Importing NgcCookieConsentModule which does not have a ɵmod property
Doing the same steps in an Angular 12 project works fine.