Angular 7 个测试用例抛出广播错误

Angular 7 test case throwing broadcaster error

while 运行 测试用例抛出这个错误。 几乎添加了所有必需的组件和服务以及其他依赖项,尽管它在 Angular &

中的 运行 测试用例时抛出错误
Error: StaticInjectorError(DynamicTestModule)[Broadcaster]: 
  StaticInjectorError(Platform: core)[Broadcaster]: 
    NullInjectorError: No provider for Broadcaster!

这是规范文件代码

import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {HttpClientModule} from '@angular/common/http';
import {RouterModule, Routes} from '@angular/router';
import { FormsModule } from '@angular/forms';
import {APP_BASE_HREF} from '@angular/common';


import {CustomiseMenuComponent} from './customise-menu.component';

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

    const appRoutes: Routes = [
        {path: 'designs', component: CustomiseMenuComponent}
    ];

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [
                CustomiseMenuComponent,
            ],
            imports: [
                FormsModule,
                HttpClientModule,
                RouterModule.forRoot(appRoutes)
            ],
            providers: [
                {provide: APP_BASE_HREF, useValue : '/' }
            ]
        }).compileComponents();
    }));

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

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

这可能是关键词:“没有广播公司的提供商!”。我想,您应该将 Broadcaster 添加到 "AppModule" 文件中的 "providers" 数组。

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    ...
  ],
  providers: [
    ...
    Broadcaster,
    ...
  ],
  bootstrap: [
    AppComponent
  ]

更新: 如果您正在使用此服务,也许您可​​以在此处查看文档: https://github.com/ranbuch/ng-broadcaster