cypress-each icon indicating copy to clipboard operation
cypress-each copied to clipboard

Problem with dynamically specifying array for each

Open appukuttan-shailesh opened this issue 3 years ago • 1 comments

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 image

Can you help me identify what I am doing wrong?

appukuttan-shailesh avatar Jan 27 '22 13:01 appukuttan-shailesh