SSh
01/31/2023, 12:27 PMimport {MessageConsumerPact, synchronousBodyHandler} from "@pact-foundation/pact"
import {uuid} from "@pact-foundation/pact/src/dsl/matchers"
it("uuid", async () => {
return new MessageConsumerPact({
consumer: "consumer",
provider: "provider",
})
.expectsToReceive("uuid")
.withContent({
uuid: uuid("cc85f093-abe3-48d8-b187-32439d5b763e"),
})
.verify(synchronousBodyHandler(async () => new Promise((resolve) => {
resolve("OK")
})))
})
but this (use uuid from v3 package)
import {MessageConsumerPact, synchronousBodyHandler} from "@pact-foundation/pact"
import {uuid} from "@pact-foundation/pact/src/v3/matchers"
it("uuid", async () => {
return new MessageConsumerPact({
consumer: "consumer",
provider: "provider",
})
.expectsToReceive("uuid")
.withContent({
uuid: uuid("cc85f093-abe3-48d8-b187-32439d5b763e"),
})
.verify(synchronousBodyHandler(async () => new Promise((resolve) => {
resolve("OK")
})))
})
throw error like this
TS2345: Argument of type '{ uuid: RegexMatcher; }' is not assignable to parameter of type 'AnyTemplate'. Types of property 'uuid' are incompatible. Type 'RegexMatcher' is not assignable to type 'string | number | boolean | JsonArray | JsonMap | Matcher<AnyTemplate> | ArrayMatcher<AnyTemplate> | TemplateMap | ArrayTemplate'. Type 'RegexMatcher' is not assignable to type 'TemplateMap'. Index signature for type 'string' is missing in type 'RegexMatcher'.SSh
01/31/2023, 12:28 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
SSh
02/01/2023, 10:43 AMMatt (pactflow.io / pact-js / pact-go)
Timothy Jones
02/02/2023, 2:23 AMAnyJson typesTimothy Jones
02/02/2023, 2:24 AMTimothy Jones
02/02/2023, 2:24 AMTimothy Jones
02/02/2023, 2:27 AMAnyTemplate type is that it prevents things like Date being inappropriately passed to the JSON expectations. The drawback is that it won’t let you use things that are interfaces without an index signature or freezing the object.Timothy Jones
02/02/2023, 2:28 AMTimothy Jones
02/02/2023, 2:30 AMTimothy Jones
02/02/2023, 2:31 AMTimothy Jones
02/02/2023, 2:32 AMas AnyTemplate.