Получение ошибки Неожиданное значение «undefined», объявленное модулем «DynamicTestModule» - PullRequest
0 голосов
/ 10 января 2020

Я проверил несколько ответов в переполнении стека, но я не могу решить свою проблему

Вот мой код для Spe c file

    import { async, ComponentFixture, TestBed } from '@angular/core/testing';
    import { DashboardComponent } from './dashboard.component';
    import { MatMenuModule} from '@angular/material/menu';
    import { DashboardModule } from './dashboard.module';
    import { DataService } from 'src/app/shared/data.service';




    describe('DashboardComponent.forRoot()', () => {
      let component: DashboardComponent;
      let fixture: ComponentFixture<DashboardComponent>;
      let menu: MatMenuModule;

      beforeEach(async(() => {
        TestBed.configureTestingModule({
          imports:[
              DashboardModule.forRoot()
            ],
          declarations: [ DashboardComponent, menu ]
        })
        .compileComponents();
      }));

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

      it('should create', () => {
        expect(component).toBeTruthy();
      });
      it(`should not provide 'DataService' service`, () => {
        expect(() => TestBed.get(DataService)).toThrowError(/No provider for/);
        });
    });

Я получаю ниже ошибка

Failed: Unexpected value 'undefined' declared by the module 'DynamicTestModule'

Как я могу решить эту проблему?

...