gpt4 book ai didi

angular - 如何修复 "Error: Expected to be running in ' ProxyZone',但未找到。” 在 mocha 测试中?

转载 作者:行者123 更新时间:2023-12-03 16:29:44 27 4
gpt4 key购买 nike

我正在尝试使用 测试我的《英雄之旅》Angular 应用程序 Mocha , & webpack .我已关注 this post以及在 this guide 的帮助下,已完成设置并修复了构建错误并启动并运行了测试。

但是,除了我不使用 async() 的测试用异常(exception),我的测试失败了。在 beforeEach钩。

通过测试

  beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [HeroService, MessageService]
});
httpTestingController = TestBed.get(HttpTestingController);

let mockHeroes = [...mockData];
let mockHero = mockHeroes[0];
// let mockId = mockHero.id;

heroService = TestBed.get(HeroService);
});

afterEach(() => {
httpTestingController.verify();
});

it('is created', () => {
expect(heroService).to.exist;
});

未通过测试

//imports
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { DashboardComponent } from './dashboard.component';
import { HeroSearchComponent } from '../hero-search/hero-search.component';

import { RouterTestingModule } from '@angular/router/testing';
import { HeroService } from '../hero.service';
import { expect } from 'chai';

...

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DashboardComponent, HeroSearchComponent],
imports: [RouterTestingModule.withRoutes([])],
providers: [{ provide: HeroService, useValue: heroService }]
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DashboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should be created', () => {
expect(component).to.exist;
});

错误堆栈跟踪

1) DashboardComponent

  "before each" hook for "should be created":
Error: Expected to be running in 'ProxyZone', but it was not found.
at Function.ProxyZoneSpec.assertPresent (node_modules\zone.js\dist\proxy.js:42:19)
at runInTestZone (node_modules\zone.js\dist\async-test.js:202:23)
at D:\Practice\Tour-Of-Heroes\node_modules\zone.js\dist\async-test.js:185:17
at new ZoneAwarePromise (node_modules\zone.js\dist\zone-node.js:910:29)
at Context.<anonymous> (node_modules\zone.js\dist\async-test.js:184:20)


我试过 Angular 5 Testing: Expected to be running in 'ProxyZone', but it was not found因为我认为这是 zone.js 使用 的一些错误 Mocha ,但没有成功。

另外,我试过关注 Mocha Documentation对于异步测试,但作为初学者,对我来说有点困难。

我试过谷歌搜索,甚至在 堆栈溢出 ,但关于 的帖子数量有限 Angular Testing Mocha .
感谢任何帮助解决这个问题。

最佳答案

我在不小心使用 fakeAsync 时遇到了同样的问题在 describe功能。
删除它为我解决了这个问题。

关于angular - 如何修复 "Error: Expected to be running in ' ProxyZone',但未找到。” 在 mocha 测试中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56034177/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com