diff --git a/src/v3/matchers.spec.ts b/src/v3/matchers.spec.ts index 89a1a0dd5..0977dd248 100644 --- a/src/v3/matchers.spec.ts +++ b/src/v3/matchers.spec.ts @@ -468,5 +468,23 @@ describe("V3 Matchers", () => { }) }) }) + + describe("when no base URL is provided", () => { + it("returns regex matcher and a MockServerURL generator", () => { + let result = MatchersV3.url([ + "users", + MatchersV3.regex("\\d+", "1234"), + "posts", + "latest", + ]) + expect(result).to.deep.equal({ + "pact:matcher:type": "regex", + "pact:generator:type": "MockServerURL", + regex: ".*(\\/users\\/\\d+\\/posts\\/latest)$", + value: "http://localhost:8080/users/1234/posts/latest", + example: "http://localhost:8080/users/1234/posts/latest" + }) + }) + }) }) }) diff --git a/src/v3/matchers.ts b/src/v3/matchers.ts index ea87d3e5e..a4e8b9c82 100644 --- a/src/v3/matchers.ts +++ b/src/v3/matchers.ts @@ -237,6 +237,7 @@ export namespace MatchersV3 { interface RegexMatcher extends Matcher { regex: string + example?: string } /** @@ -382,12 +383,15 @@ export namespace MatchersV3 { } } + // Temporary fix for inconsistancies between matchers and generators. Matchers use "value" attribute for + // example values, while generators use "example" if (basePath == null) { return { "pact:matcher:type": "regex", "pact:generator:type": "MockServerURL", regex: regex + ")$", value: example, + example } } else { return {