我正在尝试使用jest
由@nrwl/nx
. 我已按照本文将我的应用程序从 using 转换karma
为jest
.
我遇到的问题是,即使我的测试通过了,由于某种原因,控制台中会显示以下错误:
console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
Error: Error: connect ECONNREFUSED 127.0.0.1:80
at Object.dispatchError (\node_modules\jsdom\lib\jsdom\living\xhr-utils.js:65:19)
at Request.client.on.err (\node_modules\jsdom\lib\jsdom\living\xmlhttprequest.js:676:20)
at Request.emit (events.js:187:15)
at Request.onRequestError (\node_modules\request\request.js:881:8)
at ClientRequest.emit (events.js:182:13)
at Socket.socketErrorListener (_http_client.js:391:9)
at Socket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19) undefined
我只有一项测试,即:
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { RouterTestingModule } from '@angular/router/testing';
import { CommonUtilsModule } from '@lib/common-utils';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule, CommonUtilsModule],
declarations: [AppComponent]
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
});
出于某种原因,如果我删除以下行,则不会显示控制台错误:
const fixture = TestBed.createComponent(AppComponent);
我已经看了几个小时的错误,但似乎无法弄清楚是什么原因造成的。我没有在我的测试或组件中执行任何 http 请求,所以不知道为什么会这样说ECONNREFUSED
.
以前有人遇到过这个错误吗?
谢谢