twinssbc / Ionic2-Calendar

A calendar component based on Ionic framework
https://ionic-calendar-demo.stackblitz.io
MIT License
387 stars 197 forks source link

Jest tests failing due to NG0202: This constructor is not compatible with Angular Dependency Injection #643

Closed bbonczek closed 1 year ago

bbonczek commented 1 year ago

When running jest tests for component that uses ionic calendar this error occurs:

NG0202: This constructor is not compatible with Angular Dependency Injection because its dependency at index 0 of the parameter list is invalid.
    This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator.

    Please check that 1) the type for the parameter at index 0 is correct and 2) the correct Angular decorators are defined for this class and its ancestors.

      at ɵɵinvalidFactoryDep (node_modules/@angular/core/fesm2020/core.mjs:4798:11)
      at NodeInjectorFactory.CalendarComponent_Factory [as factory] (ng:/CalendarComponent/ɵfac.js:5:45)
      at getNodeInjectable (node_modules/@angular/core/fesm2020/core.mjs:3523:44)
      at instantiateAllDirectives (node_modules/@angular/core/fesm2020/core.mjs:12689:27)
      at createDirectivesInstances (node_modules/@angular/core/fesm2020/core.mjs:12113:5)
      at ɵɵelementStart (node_modules/@angular/core/fesm2020/core.mjs:15243:9)
      at CalendarComponent_Template (ng:/CalendarComponent.js:16:9)
      at executeTemplate (node_modules/@angular/core/fesm2020/core.mjs:12084:9)
      at renderView (node_modules/@angular/core/fesm2020/core.mjs:11906:13)
      at renderComponent (node_modules/@angular/core/fesm2020/core.mjs:13092:5)
      at renderChildComponents (node_modules/@angular/core/fesm2020/core.mjs:11765:9)
      at renderView (node_modules/@angular/core/fesm2020/core.mjs:11931:13)
      at renderComponent (node_modules/@angular/core/fesm2020/core.mjs:13092:5)
      at renderChildComponents (node_modules/@angular/core/fesm2020/core.mjs:11765:9)
      at renderView (node_modules/@angular/core/fesm2020/core.mjs:11931:13)
      at ComponentFactory.create (node_modules/@angular/core/fesm2020/core.mjs:13871:13)
      at initComponent (node_modules/@angular/core/fesm2020/testing.mjs:26224:51)
      at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (node_modules/zone.js/bundles/zone-testing-bundle.umd.js:409:30)
      at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (node_modules/zone.js/bundles/zone-testing-bundle.umd.js:3830:43)
      at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (node_modules/zone.js/bundles/zone-testing-bundle.umd.js:408:56)
      at Object.onInvoke (node_modules/@angular/core/fesm2020/core.mjs:26231:33)
      at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (node_modules/zone.js/bundles/zone-testing-bundle.umd.js:408:56)
      at Zone.Object.<anonymous>.Zone.run (node_modules/zone.js/bundles/zone-testing-bundle.umd.js:169:47)
      at NgZone.run (node_modules/@angular/core/fesm2020/core.mjs:26085:28)
      at TestBedImpl.createComponent (node_modules/@angular/core/fesm2020/testing.mjs:26227:41)

To reproduce this error run this unit test:

import { Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CalendarModule } from 'ion2-calendar';
import { CommonModule } from '@angular/common';

@Component({
  template: `
  <ion-calendar></ion-calendar>
`
})
class TestComponent {
}

fdescribe('IonicCalendar', () => {
  let fixture: ComponentFixture<TestComponent>;
  let component: TestComponent;

  beforeEach(async () => {
    fixture = TestBed.configureTestingModule({
      imports: [CalendarModule, CommonModule],
      declarations: [TestComponent]
    }).createComponent(TestComponent);

    fixture.detectChanges();

    component = fixture.componentInstance;
  });

  it('should create', () => {
    expect(component).toBeTruthy()
  })
});

Env:

twinssbc commented 1 year ago

ion2-calendar is not the package name of this git repo.