Hi! based on a quick search, there might not be a ...
# pact-js
t
Hi! based on a quick search, there might not be a way to verify an array contains some elements, unless using Pactv4. In which case, how would I go about testing the response contains at least "A", "C" and "D"? Thanks
Copy code
{
  "_internal": {
    "entries": [
      {
        "data": {
          "value": [
            "A",
            "B",
            "C",
            "D",
            "E"
          ]
        }
      }
    ]
  }
}
Copy code
.willRespondWith(200, (builder) => {
      builder
        .jsonBody({
          _internal: {
            entries: [{
              data: {
                value: arrayContaining("A", "C", "D")
              }
            }]
          }
        })
m
Yes something like that, is it not working as you expected?
And yes, it’s a V4 thing
t
in the contract, the response looks like:
Copy code
"data": [
                      null,
                      null,
                      null
                    ]
and in the matcher section:
Copy code
"matchers": [
                {
                  "match": "arrayContains",
                  "variants": [
                    {
                      "index": 0,
                      "rules": {}
                    },
                    {
                      "index": 1,
                      "rules": {}
                    },
                    {
                      "index": 2,
                      "rules": {}
                    }
                  ]
                }
the producer test is failing with:
Copy code
...data -> Variant at index 0 (null) was not found in the actual list
...data -> Variant at index 1 (null) was not found in the actual list
...data -> Variant at index 2 (null) was not found in the actual list
m
I think
arrayContaining
accepts an
[]
right?
oh no it’s variadic I think
t
I might schedule a call with our AM to go over this. Also perhaps the test is too value driven as opposed to shape/type driven
m
It would be best to understand the true use case (I suspect the above was just conceptual)
arrayContaining
is not an anti-pattern, but usually you can avoid it. You might be right in that it is too shape/type driven