我将mocha,chai和sinon集成到我的angular 8项目中。我使用angular-cli ng g service /path/test
不幸的是,当我启动测试时,即使由angular-cli生成且未经修改的规范也无法通过。
这是我的spec.ts文件:
import { TestBed } from '@angular/core/testing';
import { TestService } from './test.service';
describe('TestService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: TestService = TestBed.get(TestService);
expect(service).toBeTruthy();
});
});
这里是错误:
TypeError: Cannot read property 'getComponentFromError' of null
问题来自beforeEach()方法。如果我在我的beforeEach中使用来自angular / test的async:
beforeEach(async(() => TestBed.configureTestingModule({})));
我有这个新错误:
Error: the string "Zone is needed for the async() test helper but could not be found. Please make sure that your environment includes zone.js/dist/zone.js" was thrown, throw an Error :)
我不明白为什么Mocha无法管理angular-cli生成的基本测试 如何修复它们以便通过测试