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測試來運行所有測試時,彈出式對話框將停止測試。 –