michaelbazos / angular-feather

A-la-carte integration of Feather Icons in Angular applications
MIT License
155 stars 35 forks source link

Unexpected value 'FeatherModule' when developing unit tests #57

Open spoilerdo opened 2 years ago

spoilerdo commented 2 years ago

Trying to make unit tests for my components that use . For this to work I need to import the FeatherModule. But when running the unit tests I keep getting the following error:

Unexpected value 'FeatherModule' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation.

      at verifySemanticsOfNgModuleDef (../packages/core/src/render3/jit/module.ts:200:13)
      at ../packages/core/src/render3/jit/module.ts:211:5
          at Array.forEach (<anonymous>)
      at verifySemanticsOfNgModuleDef (../packages/core/src/render3/jit/module.ts:209:58)
      at Function.get (../packages/core/src/render3/jit/module.ts:169:13)
      at R3TestBedCompiler.Object.<anonymous>.R3TestBedCompiler.applyProviderOverridesToModule (../packages/core/testing/src/r3_test_bed_compiler.ts:414:49)
      at R3TestBedCompiler.Object.<anonymous>.R3TestBedCompiler.compileTestModule (../packages/core/testing/src/r3_test_bed_compiler.ts:677:10)
      at R3TestBedCompiler.Object.<anonymous>.R3TestBedCompiler.finalize (../packages/core/testing/src/r3_test_bed_compiler.ts:245:10)
      at TestBedRender3.get (../packages/core/testing/src/r3_test_bed.ts:380:43)
      at TestBedRender3.Object.<anonymous>.TestBedRender3.inject (../packages/core/testing/src/r3_test_bed.ts:278:25)
      at TestBedRender3.Object.<anonymous>.TestBedRender3.createComponent (../packages/core/testing/src/r3_test_bed.ts:335:40)
      at Function.Object.<anonymous>.TestBedRender3.createComponent (../packages/core/testing/src/r3_test_bed.ts:182:33)
      at projects/pig-settings-library/src/lib/components/employee/employee.component.spec.ts:69:23
      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)

I also tried to add a IconModule and import that one to my unit test but got the same result.

This is my Unit test setup code:

  let component: EmployeeComponent;
  let fixture: ComponentFixture<EmployeeComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [EmployeeComponent, DataGridComponent, CustomLoadingComponent],
      imports: [CommonModule, AgrovisionAngularSharedModule, HttpClientTestingModule, IconsModule, ...materialModules],
      providers: [
        { provide: EmployeeService, useValue: mockEmployeeService },
        { provide: ColumnBuilderService, useValue: mockColumnBuilderService },
        { provide: TranslationService, useValue: mockTranslationService },
      ],
    }).compileComponents();
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(EmployeeComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

Currently using version 6.2.0 because 6.3.0 is not working for me cause of my Angular version. Anyone know a solution for this?

AurelienLoyer commented 1 year ago

+1 same issue here, moving to version 6.3.0

image

I'm currently in Angular 12.x , i will be back with more information after the migration, it look like version 6.3.0 have been introduce for Angular 13+