Skip to content

Commit

Permalink
Merge pull request #22 from a4elru/21-fix-eachlike-in-strict-mode
Browse files Browse the repository at this point in the history
fix eachLike in strict mode
  • Loading branch information
ASaiAnudeep authored Aug 6, 2023
2 parents 883c5d1 + d7870bb commit 52a6ef0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pactum-matchers",
"version": "1.1.5",
"version": "1.1.6",
"description": "collection of json matchers for contract testing",
"main": "./src/index.js",
"types": "./src/index.d.ts",
Expand Down
6 changes: 4 additions & 2 deletions src/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ function compareWithRuleType(actual, expected, rules, regex_rules, path, rule) {
if (actual.length < rule.min) {
throw `Json doesn't have 'array' with min length of '${rule.min}' at '${path}' but found 'array' with length '${actual.length}'`;
}
for (let i = 0; i < actual.length; i++) {
_compare(actual[i], expected[0], rules, regex_rules, `${path}[${i}]`);
if (rule.min > 0 || typeof expected[0] !== 'undefined') {
for (let i = 0; i < actual.length; i++) {
_compare(actual[i], expected[0], rules, regex_rules, `${path}[${i}]`);
}
}
} else {
arrayCompare(actual, expected, rules, regex_rules, path);
Expand Down
14 changes: 14 additions & 0 deletions test/compare.eachLike.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ test('root object', () => {
assert.equal(message, '');
});

test('root object - empty array in strict mode', () => {
const actual = [];
const value = eachLike({
name: 'snow',
age: 18
}, {
min: 0
});
const rules = setMatchingRules({}, value, '$.body');
const expected = getValue(value);
const { message } = compare(actual, expected, rules, '$.body', true);
assert.equal(message, '');
});

test('root object - one object fails', () => {
const actual = [
{
Expand Down

0 comments on commit 52a6ef0

Please sign in to comment.