<#1398 Getting error: connect ECONNREFUSED ::1:&lt...
# pact-js-development
g
#1398 Getting error: connect ECONNREFUSED ::1:&lt;port&gt; using PactV3 and Jest Issue created by pulak777 ### Software versions Please provide at least OS and version of pact-js • OS: Windows 11 Enterprise • Consumer Pact library: Pact JS v14.0.0 • Node Version: v18.20.2 ### Issue Checklist Please confirm the following: • [ *] I have upgraded to the latest • I have the read the FAQs in the Readme • I have triple checked, that there are no unhandled promises in my code and have read the section on intermittent test failures • I have set my log level to debug and attached a log file showing the complete request/response cycle • For bonus points and virtual high fives, I have created a reproduceable git repository (see below) to illustrate the problem ### Expected behaviour fill in here ### Actual behaviour
Copy code
Error: Error: connect ECONNREFUSED ::1:1234
        at Object.dispatchError (C:\app\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\living\xhr\xhr-utils.js:63:19)
        at Request.<anonymous> (C:\app\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\living\xhr\XMLHttpRequest-impl.js:655:18)
        at Request.emit (node:events:529:35)
        at Request.emit (node:domain:489:12)
        at ClientRequest.<anonymous> (C:\app\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\living\helpers\http-request.js:121:14)
        at ClientRequest.emit (node:events:517:28)
        at ClientRequest.emit (node:domain:489:12)
        at Socket.socketErrorListener (node:_http_client:501:9)
        at Socket.emit (node:events:517:28)
        at Socket.emit (node:domain:489:12)
        at emitErrorNT (node:internal/streams/destroy:151:8)
        at emitErrorCloseNT (node:internal/streams/destroy:116:3)
        at processTicksAndRejections (node:internal/process/task_queues:82:21) {
      type: 'XMLHttpRequest'
    }

      at VirtualConsole.<anonymous> (node_modules/jest-environment-jsdom/build/index.js:63:23)
### Steps to reproduce How can someone else reproduce this bug? // jest.config.pact
Copy code
import { JestConfigWithTsJest } from 'ts-jest';

const esModules = [
  '.*\\.mjs$',
  'lodash-es',
  'color-alpha',
  'color-name',
  'color-parse',
].join('|');

const config: JestConfigWithTsJest = {
  roots: ['src'],
  testMatch: ['**/?(*.)+(pact).ts'],
  preset: 'jest-preset-angular',
  setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
  transformIgnorePatterns: [`node_modules/(?!${esModules})`],
  testEnvironmentOptions: {
    url: '<http://localhost:1234>',
  },
  verbose: true,
  collectCoverage: false,
  moduleNameMapper: {
    '^color\\-alpha$': '<rootDir>/node_modules/color-alpha',
    '^color\\-name$': '<rootDir>/node_modules/color-name',
    '^color\\-parse$': '<rootDir>/node_modules/color-parse',
  },
};

export default config;
// setup-jest
Copy code
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';

setupZoneTestEnv();
// test.pact
Copy code
describe('/test-api with Pact', () => {
  const provider: PactV3 = new PactV3({
    consumer: 'test-ui',
    port: 1234,
    host: 'localhost',
    provider: 'test-app',
    logLevel: 'debug',
  });

  beforeEach(async () => {
    TestBed.configureTestingModule({
      imports: [HttpClientModule],
      providers: [TestService],
      teardown: { destroyAfterEach: false },
    });
  });

  describe('test service returns', () => {
    const interaction: V3Interaction = {
      states: [{ description: 'some description' }],
      uponReceiving: 'some description',
      willRespondWith: {
        body: testlMatcher,
        status: 200,
      },
      withRequest: {
        method: 'GET',
        path: `v1/test/url`,
      },
    };

    beforeAll(() => {
      provider.addInteraction(interaction);
    });

    it('test scenario', async () => {
      const testService = TestBed.inject(
        TestService,
      );
      await testService
        .testMethod()
        .toPromise()
        .then((testResponse) => {
          expect(testResponse).toEqual(
            mockResponse,
          );
        });
    });
  });
});
### Relevant log files Please ensure you set logging to
DEBUG
and attach any relevant log files here (or link to a gist).
NA pact-foundation/pact-js