Angular 8 测试错误 模块导入的意外值 'DecoratorFactory' 'DynamicTestModule'

Angular 8 testing error Unexpected value 'DecoratorFactory' imported by the module 'DynamicTestModule'

我正在尝试将 Jasmine & Karma 框架添加到当前的 angular 应用程序 运行 版本 8.2 中。但是我在 Karma 测试中遇到了这个奇怪的错误 运行 window:

Failed: Unexpected value 'DecoratorFactory' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation.

问题是什么?

我的 componenent.spec.ts 看起来像这样:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HomeComponent } from './home.component';
import { NO_ERRORS_SCHEMA} from '@angular/core';
import {RouterTestingModule} from '@angular/router/testing';
import {HttpClientTestingModule} from '@angular/common/http/testing';
import { MsalService } from '@azure/msal-angular';
import { Store } from '@ngrx/store';
import { Pipe } from '@angular/core';


describe('HomeComponent', () => {
  let component: HomeComponent;
  let fixture: ComponentFixture<HomeComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
       imports: [RouterTestingModule, HttpClientTestingModule, Pipe]
      ,declarations: [HomeComponent]
      ,schemas:[NO_ERRORS_SCHEMA]
      ,providers: [
        {provide: MsalService, useFactory: '' },
        {provide: Store, useFactory: '' }
      ]
    })
    .compileComponents();
  }));

    it('should have header text', async(() => {
      const fixture = TestBed.createComponent(HomeComponent);
      fixture.detectChanges();
    
      const compiled = fixture.debugElement.nativeElement;
      //expect(compiled.querySelector('.header-txt').textContent).toContain('Tax');    
  }));
});

我找到了原因:-

export class MockStore<T> {
      private state: BehaviorSubject<T> = new BehaviorSubject(undefined);
      
      setState(data: T) { this.state.next(data); }

      select(selector?: any): Observable<T> {
        return this.state.asObservable();
      }

      pipe() {}
      dispatch(action: any) { }
}

============================================= ===========================

 TestBed.configureTestingModule({
    {provide: Store, useFactory: 'MockStore' }
    ..............

useFactory 属性 必须是一些自定义 class 名称。现在我嘲笑商店class。