cypress-each
cypress-each copied to clipboard
Problem with dynamically specifying array for each
I need to fetch the array from an API. As example, from here: https://jsonplaceholder.cypress.io/users?_limit=3
This needs to be done prior to running any of the tests, and so I wish add it to the before() or beforeEach() functions, save them into a variable (or alias) and then use in the tests. I try this but it fails:
describe.only('my tests', function () {
beforeEach(() => {
cy.request(
"GET",
"https://jsonplaceholder.cypress.io/users?_limit=3"
).its('body')
.as('data')
})
it.each(this.data)('has correct types', function (item) {
expect(item.id).to.be.a('number')
expect(item.name).to.be.a('string')
})
})
(code based on my understanding of docs here)
But I keep getting this error:
cypress-each: values must be an array
Can you help me identify what I am doing wrong?