我试图测试在角弹出一个组成部分,我不知道为什么,当我启动测试我得到一个错误,指出:
“垫分压器”不是已知的元件:1.如果“垫分压器”是角度成分,然后验证它是该模块的一部分。 2.如果“垫除法”是一个Web组件,然后添加“CUSTOM_ELEMENTS_SCHEMA”到“@ NgModule.schemas”这个成分对抑制此消息。
我进口它虽然在这里@NgModule我的代码:
@NgModule({
declarations: [
AppComponent,
AdminTopMenuComponent,
SvGameCardComponent,
SvCreationPopupComponent,
MockPopupComponent,
MyDialogComponent,
FvCreationPopupComponent,
GameModesComponent,
LinkTestComponent,
UserComponent,
],
imports: [
BrowserModule,
HttpClientModule,
AppRoutingModule,
FormsModule,
ReactiveFormsModule,
MatDialogModule,
BrowserAnimationsModule,
MatButtonModule,
MatCheckboxModule,
MatTableModule,
MatDividerModule,
MatInputModule,
MatSelectModule,
MatFormFieldModule,
MatCardModule,
AppRoutingModule,
RouterModule,
],
exports: [
MatDividerModule,
MatFormFieldModule,
],
providers: [BasicService],
bootstrap: [AppComponent],
entryComponents: [
MyDialogComponent,
SvCreationPopupComponent,
FvCreationPopupComponent,
]
})
export class AppModule {
}
@Component({
selector: 'app-fv-creation-popup',
templateUrl: './fv-creation-popup.component.html',
styleUrls: ['./fv-creation-popup.component.css']
})
export class FvCreationPopupComponent implements OnInit {
constructor(
public dialogRef: MatDialogRef<FvCreationPopupComponent>, // dialogRef is now a reference to the diaolog popup
@Inject(MAT_DIALOG_DATA) public data: any) { } // allows the sharing of data through dialogConfig.data
ngOnInit() {
}
submit(): void {
//TODO: implementation de la fonction
console.log("Submit fv-gameCard not implemented")
}
close(): void {
this.dialogRef.close();
}
gameType: string[] = ["Formes géométriques","Thématique"];
}
import { /*async,*/ async, ComponentFixture, TestBed } from "@angular/core/testing";
import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from "@angular/material";
import { FvCreationPopupComponent } from "./fv-creation-popup.component";
describe("FvCreationPopupComponent", () => {
let component: FvCreationPopupComponent;
let fixture: ComponentFixture<FvCreationPopupComponent>;
// const mock: MatDialogRef<FvCreationPopupComponent> = new MatDialogRef<FvCreationPopupComponent>(null, null) ;
beforeEach(async(() => {
// const data: MyDialogComponent = null;
// data.message = "Dialog Message";
// tslint:disable-next-line:typedef
const mockDialogRef = {
close: jasmine.createSpy("close"),
};
TestBed.configureTestingModule({
imports: [MatDialogModule],
declarations: [ FvCreationPopupComponent ],
providers: [{ provide: MatDialogRef, useValue: {mockDialogRef} }, { provide: MAT_DIALOG_DATA, useValue: {} } ]})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FvCreationPopupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it("should create", () => {
expect(component).toBeTruthy();
});
});
我认为你必须包括你的测试模块内部的MatDividerModule,你将不得不在组件中使用,以及其他模块做同样的:
import { MatDialogModule, MatDialogRef, MAT_DIALOG_DATA } from "@angular/material";
import { FvCreationPopupComponent } from "./fv-creation-popup.component";
describe("FvCreationPopupComponent", () => {
let component: FvCreationPopupComponent;
let fixture: ComponentFixture<FvCreationPopupComponent>;
// const mock: MatDialogRef<FvCreationPopupComponent> = new MatDialogRef<FvCreationPopupComponent>(null, null) ;
beforeEach(async(() => {
// const data: MyDialogComponent = null;
// data.message = "Dialog Message";
// tslint:disable-next-line:typedef
const mockDialogRef = {
close: jasmine.createSpy("close"),
};
TestBed.configureTestingModule({
imports: [MatDialogModule, MatDividerModule, ...],
declarations: [ FvCreationPopupComponent ],
providers: [{ provide: MatDialogRef, useValue: {mockDialogRef} }, { provide: MAT_DIALOG_DATA, useValue: {} } ]})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FvCreationPopupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it("should create", () => {
expect(component).toBeTruthy();
});
});