Hello, please help me with the below issue. I am t...
# pact-js
h
Hello, please help me with the below issue. I am trying to use eachLike matcher in my consumer test, but am not getting the desired result as the provider test is failing. The consumer code is :-
Copy code
authors: eachLike(['Harry', 'Garry', 'Reilly']),
and this is the provider's mock data against which its running the tests :-
Copy code
"authors": ["Frances", "Gibbs"],
And I am getting the below error :-
Copy code
1.2) body: $.featured.authors.0 Type mismatch: Expected List ["Harry","Federer","Rilos"] but received String 'Frances'

        -[
        -  "Harry",
        -  "Federer",
        -  "Rilos"
        -]
        +"Frances"


    1.3) body: $.featured.authors.1 Type mismatch: Expected List ["Harry","Federer","Rilos"] but received String 'Gibbs'

        -[
        -  "Harry",
        -  "Federer",
        -  "Rilos"
        -]
        +"Gibbs"
u
eachLike
takes a single example and ensures all items in the list match that example. So
authors: eachLike('Harry'),
☝️ 1
m
So basically, don’t pass an array to
eachLike
otherwise you’re expecting an array of arrays
h
Please suggest a way to validate an array in that case.
The documentation suggests using eachLike for arrays
m
yes, it’s for arrays, but you usually don’t supply an array for that argument i.e. don’t do
Copy code
authors: eachLike(['Harry', 'Garry', 'Reilly']),
do
Copy code
authors: eachLike('Harry'),
The first one tries to match a structure like this:
Copy code
authors: [['Harry', 'Garry', 'Reilly']]
The second one matches a structure like this:
Copy code
authors: ['Harry', 'Garry', 'Reilly']
eachLike
is used for a property, where each (implies an array) item in the array is like <sample>
if sample is a number, it will match an array of numbers. If it’s a string, an array of strings. If an array, an array of arrays… and so on
h
okay, got it now, thankyou!
🙌 1
I tried the following code :-
Copy code
authors: eachLike('Harry')
and got the following error :-
Copy code
1.1) body: $.featured Actual map is missing the following keys: topic

        {
          "authors": [
        -    "Harry"
        +    "Federer",
        +    "Rilose"
          ],
any resolution for this please?
Why is it looking for an absolute value match inspite of using a matcher here?
m
Can you please share the output pact and ideally the
trace
level logs for this test?
h
The tests passed after I removed the 'topic' attribute as mentioned in the above screenshot, but the logs confused me as they seemed to be expecting an absolute value match, even though the tests passed.
🤔 1