Angular 获取意外值时出错';未定义';由模块';动态测试模块';
我在堆栈溢出中检查了一些答案,但我无法解决我的问题 这是我的规范文件代码Angular 获取意外值时出错';未定义';由模块';动态测试模块';,angular,jasmine,karma-jasmine,angular-test,Angular,Jasmine,Karma Jasmine,Angular Test,我在堆栈溢出中检查了一些答案,但我无法解决我的问题 这是我的规范文件代码 import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { DashboardComponent } from './dashboard.component'; import { MatMenuModule} from '@angular/material/menu'; import {
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/);
});
});
如何解决此问题?
菜单
未定义。您想改用MatMenuModule
吗?@yurzui菜单我已经在声明权限中声明过了Yep。但是您还没有将它分配给任何东西。我删除了它,但仍然得到相同的错误失败:模块'DynamicTestModule'声明的意外值'undefined'
Failed: Unexpected value 'undefined' declared by the module 'DynamicTestModule'