angular - zone.js 预计将在 ProxyZone 中运行
问题描述
我觉得这个问题已经被问过很多次了,但是我找到的解决方案都没有帮助,我有点迷失了我的问题的原因。解决方案通常建议将 async/fakeAsync 调用设置在错误的位置(例如,describe 而不是 beforeEach)或完全删除 async 但这些都不起作用,因为这是一个普通生成的测试,我希望它只是跑。
因此,无论我想运行什么测试用例,我都面临以下问题:
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 测试 --include=**/test-case.component.spec.ts
我正在使用 zone.js 版本 0.11.4
解决方案
好吧,只是我在这里发布了我的问题,我想通了......在解决问题的几次尝试之一中,我添加了这一行
import 'zone.js/dist/zone-testing.js'
到我的 pollyfills.ts 文件。
但是这里似乎不需要它,必须在 test.ts 文件的最开始添加。
推荐阅读
- python - Pyinstaller ImportError 在自己的模块上
- node.js - 如何使用 Sequelize 设置数据库故障转移门户?
- python - 箱线图中没有异常值检测
- asp.net - Ajax 调用未从 API 获取 json 格式的数据
- javascript - 多维数组——新变量查询
- expo - 尝试构建时的 Expo 错误:不支持的 SDK 版本:我们的应用程序构建器不支持 33.0.0 版本
- r - 如何解析符号的值而不是符号的名称
- aws-lambda - AWS Lamda 错误:解析错误:意外的令牌客户端
- php - 如何使用 laravel 将 csv 文件保存在 /public 文件夹中?
- django-filter - 无法在 graphene-django 中使用 django 过滤器按两个字段排序