在Angular 8中,如果你在单元测试中遇到了加载mat-modules的问题,可以按照以下步骤解决:
import { MatButtonModule } from '@angular/material/button';
import { TestBed, async } from '@angular/core/testing';
import { MatButtonModule } from '@angular/material/button';
describe('YourComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MatButtonModule
],
declarations: [
YourComponent
],
}).compileComponents();
}));
});
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { MatButtonModule } from '@angular/material/button';
import { YourComponent } from './your.component';
describe('YourComponent', () => {
let component: YourComponent;
let fixture: ComponentFixture;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MatButtonModule
],
declarations: [
YourComponent
],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(YourComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
通过以上步骤,你应该能够在Angular 8的单元测试中成功加载mat-modules。请注意,你可能需要根据你的具体情况调整以上代码示例。