我在Stack Overflow中检查了几个答案,但无法解决我的问题
这是我的Spec文件代码
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'
我该如何解决?