jest-preset-angular: Jsdom 13 error connect ECONNREFUSED 127.0.0.1:80 even all test passed

hi team. I’m new to Jest and try to add it to my Angular app. For now, all the test is passed but this error is repeatedly produced. Seem like jest does not mock the http request or jsdom can not handle http mocking. Can anyone help me out? I tried to research but can not find any solution.

console.error node_modules/jest-environment-jsdom-thirteen/node_modules/jsdom/lib/jsdom/virtual-console.js:29
    Error: Error: connect ECONNREFUSED 127.0.0.1:80
        at Object.dispatchError (D:\EMP-APP\node_modules\jest-environment-jsdom-thirteen\node_modules\jsdom\lib\jsdom\living\xhr-utils.js:60:19)
        at Request.client.on.err (D:\EMP-APP\node_modules\jest-environment-jsdom-thirteen\node_modules\jsdom\lib\jsdom\living\xmlhttprequest.js:674:20)
        at Request.emit (events.js:198:15)
        at Request.onRequestError (D:\EMP-APP\node_modules\request\request.js:881:8)
        at ClientRequest.emit (events.js:193:13)
        at Socket.socketErrorListener (_http_client.js:397:9)
        at Socket.emit (events.js:193:13)
        at emitErrorNT (internal/streams/destroy.js:91:8)
        at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
        at processTicksAndRejections (internal/process/task_queues.js:81:17) undefined

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19

Most upvoted comments

This is what I’m using for my jest.config.js file:

console.log('loading jest.config.js file');
module.exports = {
    preset: 'jest-preset-angular',
    setupFilesAfterEnv: ['<rootDir>/tests/client/jest-setup.ts'],
    globals: {
        'ts-jest': {
            tsConfig: '<rootDir>/tsconfig.test.json',
            diagnostics: true,
            stringifyContentPathRegex: '\\.html$',
            astTransformers: [require.resolve('jest-preset-angular/InlineHtmlStripStylesTransformer')],
        },
    }
};

Take a look at my comment here for the full explanation: https://github.com/thymikee/jest-preset-angular/issues/286#issuecomment-519050423

@wtho I have been receiving this error myself but I think it is environment based. I recently ported over my company’s CI from Jenkins to Github Actions. While the tests passed fined this error does pop up. I’ve been trying to figure it out but to no avail.

● Console

console.error node_modules/jest-environment-jsdom-sixteen/node_modules/jsdom/lib/jsdom/virtual-console.js:29
  Error: Error: connect ECONNREFUSED 127.0.0.1:80
      at Object.dispatchError (/home/runner/work/web/web/node_modules/jest-environment-jsdom-sixteen/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:62:19)
      at Request.<anonymous> (/home/runner/work/web/web/node_modules/jest-environment-jsdom-sixteen/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:654:18)
      at Request.emit (events.js:327:22)
      at Request.onRequestError (/home/runner/work/web/web/node_modules/request/request.js:877:8)
      at ClientRequest.emit (events.js:315:20)
      at Socket.socketErrorListener (_http_client.js:426:9)
      at Socket.emit (events.js:315:20)
      at emitErrorNT (internal/streams/destroy.js:92:8)
      at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)

@jackmercy , the way I fixed mine was taking a step back and creating a new setup.jest.ts based on the defaults specified on the documentation. Then adding item by item to check what was breaking.

In my case, I end up realising that jest-preset-angular sits on top of ts-jest and it’s logic it’s all around setting up ts-jest to work with Angular. If you check the source code, you can see what’s the default preset is.

Then I started adding the preset values and it all worked out. You can check my repo setup. There’s not much but it has libraries added with tests. Jest is configured to get code coverage and html reports to be used on CI/CD pipeline and the results are also used within Storybook.

Let me know if you need any clarification 😃