我觉得这个问题已经被问过很多次了,但是我发现的解决方案没有一个是帮助我的,我有点迷失了我的问题的原因。解决方案通常建议将异步/fakeAsync调用设置在错误的位置(例如,describe而不是beforeEach),或者完全删除异步,但不起作用,而且由于这是一个简单生成的测试,我希望它只是运行。
因此,无论我想运行什么测试用例,我都面临以下问题:
Error: Expected to be running in 'ProxyZone', but it was not found.
at Function.assertPresent (node_modules/zone.js/dist/zone-testing.js:215:23)
at Object.resetFakeAsyncZone (node_modules/zone.js/dist/zone-testing.js:1997:54)
at resetFakeAsyncZone (packages/core/testing/src/fake_async.ts:23:32)
at UserContext.<anonymous> (packages/core/testing/src/before_each.ts:26:5)
at <Jasmine>我尝试使用一个完全空的和新生成的组件,其中测试用例是由cli自动生成的,而且它也失败了。下面是测试用例组件测试:
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TestCaseComponent } from './test-case.component';
describe('TestCaseComponent', () => {
let component: TestCaseComponent;
let fixture: ComponentFixture<TestCaseComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ TestCaseComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(TestCaseComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});我使用以下命令运行测试:
ng测试--包括=**/ test -Case.Component.spec.ts
我使用的是zone.js版本0.11.4
发布于 2021-10-13 13:39:33
只是我把我的问题发到这里我想明白了.在解决这个问题的几次尝试中,我添加了这一行
import 'zone.js/dist/zone-testing.js'到我的pollyfills.ts文件。
但是,这里似乎不需要它,必须在test.ts文件的开头添加它。
https://stackoverflow.com/questions/69556464
复制相似问题