Skip to content

Commit b3f6062

Browse files
committed
support regex default value
1 parent e294ebe commit b3f6062

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pactum-matchers",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "collection of json matchers for contract testing",
55
"main": "./src/index.js",
66
"types": "./src/index.d.ts",

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ function string(value) {
5555
}
5656

5757
function regex(value, matcher) {
58+
if (typeof matcher === 'undefined') {
59+
matcher = value;
60+
value = 'regex';
61+
}
5862
if (matcher instanceof RegExp) {
5963
matcher = matcher.source;
6064
}

test/rules.regex.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,15 @@ test('regex - multiple prop in nested objects', () => {
5252
});
5353
});
5454

55+
test('regex - root without value', () => {
56+
const value = regex(/\w+/);
57+
const rules = setMatchingRules({}, value, '$.body');
58+
assert.deepStrictEqual(rules, {
59+
'$.body': {
60+
match: 'regex',
61+
regex: '\\w+'
62+
}
63+
});
64+
});
65+
5566
test.run();

test/value.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,14 @@ test('eachLike - multiple values with nested matchers', () => {
168168
assert.deepStrictEqual(actual, expected);
169169
});
170170

171+
test('regex', () => {
172+
const value = getValue(regex('a', /\w+/));
173+
assert.deepStrictEqual(value, 'a');
174+
});
175+
176+
test('regex default', () => {
177+
const value = getValue(regex(/\w+/));
178+
assert.deepStrictEqual(value, 'regex');
179+
});
180+
171181
test.run();

0 commit comments

Comments
 (0)