Angular Material unittest component with datepicker

187 views Asked by At

I'm trying to unittest a component which contains a Material Datepicker. I got the following error:

Error: MatDatepicker: No provider found for DateAdapter. You must import one of the following modules at your application root: MatNativeDateModule, MatMomentDateModule, or provide a custom implementation.

Obviously I added the module to my TestBed config which gives my the nest error:

Error: Unexpected value 'MatMomentDateModule' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation.

This is my setup:

beforeEach(async(() => {
  TestBed.configureTestingModule({
    declarations: [RhvCriteriaComponent],
    imports: [
      MaterialModule,
      MatMomentDateModule
    ],
    // schemas: [NO_ERRORS_SCHEMA],
    providers: [
      FormBuilder,
      { provide: LandenService, useValue: landenService },
      { provide: AutoriteitService, useValue: autoriteitenService },
      { provide: RhvSoortService, useValue: rhvSoortService },
      { provide: MAT_DATE_LOCALE, useValue: 'nl-NL' },
      { provide: MAT_AUTOCOMPLETE_DEFAULT_OPTIONS, useValue: { autoActiveFirstOption: true } }
    ]
  })
      .compileComponents();
}));

What am I missing?

0

There are 0 answers