在我的项目中,我仅启用了PathNotFoundComponent的spec文件,所有其他spec.ts文件都被注释了,并且出现了以上错误。
我的组件文件,
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-path-not-found',
templateUrl: './path-not-found.component.html',
styleUrls: ['./path-not-found.component.scss']
})
export class PathNotFoundComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
我的组件规格文件
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PathNotFoundComponent } from './path-not-found.component';
describe('PathNotFoundComponentComponent', () => {
let component: PathNotFoundComponent;
let fixture: ComponentFixture<PathNotFoundComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PathNotFoundComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PathNotFoundComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
但是此测试用例在以下情况下有效。
如果我将组件规范文件中的beforeEach更改为beforeAll。
或
在test.ts文件中将require.context('./',true,/.spec.ts$/)更改为 require.context('./',true,/path-not-found.component.spec.ts $ /)
请帮助我找到解决方案?