request is normal GET of specific ID of that collection of documents
I will try to mock response a bit, as that is sensitive data
yes let’s say to simplify I have only one expected ‘title’ in JSON test data file and in test I want to find it easily in that list of 8 titles under items property.
However final thing would be to have test which will go thru all 8 expected titles in JSON test data file and validate it against JSON response, however order is not needed, just fact if some title exists in response or not
Is it the same as the example you gave me. (Which is an array of objects).
The error message is basically telling that you response is not an array.
find is a JavaScript function\method that is only available to arrays, so if response is not an array, then the find method will not exist, so its correctly telling you that find is not a function.
now just need to make some loop and add rest of the titles into the JSON test data file, to validate whole JSON test data title against response. Can I reuse forEach function somehow?
This is an array with a single object in it (so will only run one iteration). That object has a single key called testData where the value is your array of test data.
You can then access the testData array using…
let testData = pm.iterationData.get("testData")
Or the special data variable (which contains the current iterations data).
It sounds like you want a forEach loop against the test data array, and then test to see if the current title is in the response, so yes, a forEach loop would help with this.
Define the current title in the loop as a variable, and you can then use backticks and string literals to customize the test case name, like following.
pm.test(${title} exists, () => {
Otherwise, all of the tests will have the same name, and it will be hard to work out which one has failed.