File tree 2 files changed +48
-11
lines changed
2 files changed +48
-11
lines changed Original file line number Diff line number Diff line change @@ -35,17 +35,46 @@ describe('V3 Matchers', () => {
35
35
} ) ;
36
36
37
37
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
+ } ) ;
41
52
} ) ;
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 (
45
58
{
46
59
a : 'b' ,
47
60
} ,
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
+ } ) ;
49
78
} ) ;
50
79
} ) ;
51
80
} ) ;
Original file line number Diff line number Diff line change @@ -57,11 +57,19 @@ export const eachKeyLike = <T extends AnyTemplate>(
57
57
/**
58
58
* Array where each element must match the given template
59
59
* @param template Template to base the comparison on
60
+ * @param min Minimum number of elements required in the array
60
61
*/
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
+ } ;
65
73
66
74
/**
67
75
* Like Matcher with a minimum number of required values
You can’t perform that action at this time.
0 commit comments