I'm trying to use jest
with an Angular project created by @nrwl/nx
. I have followed this article to convert my app from using karma
to jest
.
The issue I'm getting is that even though my tests are passing, for some reason the following error shows in the console:
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
I have only one test, which is:
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();
}));
});
For some reason if I take the following line out, the console error does not show:
const fixture = TestBed.createComponent(AppComponent);
I've been looking at the error for hours now, but can't seem to figure out what's causing it. I'm not doing any http request in my test or component, so no idea why it's saying ECONNREFUSED
.
Anyone had this error before?
Thanks