pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.58k stars 343 forks source link

(TypeScript) Cannot use V3 matchers within MessagePact. Types are incompatible. #1133

Closed murbanowicz closed 4 months ago

murbanowicz commented 8 months ago

Software versions

TypeScript: 5.2.2 "@pact-foundation/pact": "12.1.0"

Issue Checklist

Please confirm the following:

Expected behaviour

I should be able to use v3 matchers

Actual behaviour

Types are incompatible

Steps to reproduce

import * as path from 'path';
import { MessageConsumerPact, MatchersV3 } from '@pact-foundation/pact';

const messagePact = new MessageConsumerPact({
  consumer: 'example-shipment-service',
  dir: path.resolve(process.cwd(), 'pacts'),
  pactfileWriteMode: 'update',
  provider: 'example-orders-service',
});

describe('Consumer: example-shipment-service, Provider: example-orders-service', () => {
  it('order-confirmed event', () => {
    return messagePact.expectsToReceive('order-confirmed').withContent({
      type: MatchersV3.equal('order-confirmed'),
    });
  });
});

gives the following error:

TS2345: Argument of type { type: MatchersV3.Matcher<string>; } is not assignable to parameter of type AnyTemplate
Types of property type are incompatible.
Type Matcher<string> is not assignable to type
string | number | boolean | JsonArray | JsonMap | Matcher<AnyTemplate> | ArrayMatcher<AnyTemplate> | TemplateMap | ArrayTemplate
Type Matcher<string> is not assignable to type TemplateMap
Index signature for type string is missing in type Matcher<string>

It will only work without error when using Matchers which I believe are V2 matches and are missing quite a lot of stuff.

Relevant log files

Please ensure you set logging to DEBUG and attach any relevant log files here (or link to a gist).

mefellows commented 6 months ago

This should be fixed now in the latest release.

ferrisbuhler commented 4 months ago

@mefellows Which version of pact-js do you consider to contain the fix? With 12.1.2 (running on Windows) the problem still seems to exist.

mefellows commented 4 months ago

The fix addressed the main body but not the matchers, which I believe is what you need. It should be straightforward, I'll see if I can patch it tomorrow for you