Skip to content

Commit

Permalink
feat: support regex matcher with a regexp object
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed May 26, 2020
1 parent a2a7f55 commit d92f6f5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/v3/matchers.ts
Expand Up @@ -216,7 +216,21 @@ export function string(str: string) {
* @param pattern Regular Expression to match
* @param str Example value
*/
export function regex(pattern: string, str: string) {
export function regex(pattern: string, str: string): any
/**
* Value that must match the given regular expression
* @param pattern Regular Expression to match
* @param str Example value
*/
export function regex(pattern: RegExp, str: string): any
export function regex(pattern: any, str: string): any {
if (pattern instanceof RegExp) {
return {
"pact:matcher:type": "regex",
regex: pattern.toString(),
value: str,
}
}
return {
"pact:matcher:type": "regex",
regex: pattern,
Expand Down

0 comments on commit d92f6f5

Please sign in to comment.