Skip to content

Commit 18dbfd4

Browse files
committed
fix: missing min in v3 eachLike #958
1 parent a3e6b65 commit 18dbfd4

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

src/v3/matchers.spec.ts

+36-7
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,46 @@ describe('V3 Matchers', () => {
3535
});
3636

3737
describe('#eachLike', () => {
38-
it('returns a JSON representation of an eachLike matcher', () => {
39-
const result = MatchersV3.eachLike({
40-
a: 'b',
38+
describe('with no min', () => {
39+
it('returns a JSON representation of an eachLike matcher', () => {
40+
const result = MatchersV3.eachLike({
41+
a: 'b',
42+
});
43+
expect(result).to.deep.equal({
44+
min: 1,
45+
'pact:matcher:type': 'type',
46+
value: [
47+
{
48+
a: 'b',
49+
},
50+
],
51+
});
4152
});
42-
expect(result).to.deep.equal({
43-
'pact:matcher:type': 'type',
44-
value: [
53+
});
54+
55+
describe('with min', () => {
56+
it('returns a JSON representation of an eachLike matcher', () => {
57+
const result = MatchersV3.eachLike(
4558
{
4659
a: 'b',
4760
},
48-
],
61+
3
62+
);
63+
expect(result).to.deep.equal({
64+
min: 3,
65+
'pact:matcher:type': 'type',
66+
value: [
67+
{
68+
a: 'b',
69+
},
70+
{
71+
a: 'b',
72+
},
73+
{
74+
a: 'b',
75+
},
76+
],
77+
});
4978
});
5079
});
5180
});

src/v3/matchers.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,19 @@ export const eachKeyLike = <T extends AnyTemplate>(
5757
/**
5858
* Array where each element must match the given template
5959
* @param template Template to base the comparison on
60+
* @param min Minimum number of elements required in the array
6061
*/
61-
export const eachLike = <T extends AnyTemplate>(template: T): Matcher<T[]> => ({
62-
'pact:matcher:type': 'type',
63-
value: [template],
64-
});
62+
export const eachLike = <T extends AnyTemplate>(
63+
template: T,
64+
min = 1
65+
): MinLikeMatcher<T[]> => {
66+
const elements = min;
67+
return {
68+
min,
69+
'pact:matcher:type': 'type',
70+
value: times(() => template, elements),
71+
};
72+
};
6573

6674
/**
6775
* Like Matcher with a minimum number of required values

0 commit comments

Comments
 (0)