GitHub
03/10/2025, 3:04 PMError: 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
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
import { setupZoneTestEnv } from 'jest-preset-angular/setup-env/zone';
setupZoneTestEnv();
// test.pact
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-jsGitHub
03/11/2025, 3:04 PM