1
当我运行测试时,我得到“无法解析MdDialogRef的所有参数:(?,?)”错误。请帮忙。在测试Angular 2材质对话框组件时得到错误
请参考下面的代码进一步参考。
MyComponent.spec.ts
import { async, ComponentFixture, ComponentFixtureAutoDetect, TestBed } from '@angular/core/testing';
import { MyComponent } from './my.component';
import { MdDialogModule, MdDialog, MdDialogConfig, MdDialogRef } from '@angular/material';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
describe('Component: My Component',() => {
let component: MyComponent;
let fixture: ComponentFixture<MyComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [MyComponent],
imports: [BrowserAnimationsModule, MdDialogModule.forRoot()],
providers: [MdDialogRef],
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should, have defined component',() => {
expect(component).toBeDefined();
});
});
MyComponent.ts
import { Component } from '@angular/core';
import { MdDialog, MdDialogRef } from '@angular/material';
@Component({
templateUrl: './mys.component.html'
})
export class MyComponent {
constructor(public dialogRef: MdDialogRef<any>) { }
}
谢谢,它的工作原理:) – sandyk
噢欢迎好友:) –
有没有什么办法可以关闭对话框,我试过了'dialog.closeAll()',但它不起作用。因为当我使用ng测试来运行所有测试时,弹出式对话框将停止测试。 –