https://cypress.io logo
cy.each + Cypress.Promise not calling what's insid...
# i-need-help
m
What is up with MEE6? It was not duplicate text.
I am trying to make seven cy.requests, but I don't want to statically define each request; however, this block is only making the very first request even though it does iterate over each item.
Okay, MEE6 isn't letting me insert a code block.
Copy code
test
b
@melodic-egg-83620 can you give this another try and let me know if it works for you?
m
Copy code
const functions = []

        Client.requiredDocuments.forEach((document) => {
          const params = {
            client_id: client.id,
            document_type: document,
            url: Urls.MOCK_FILE_URL,
            name: `${document}.pdf`,
          }

          functions.push(() => {
            cy
              .request({
                headers: { authorization: accessToken },
                method: 'POST',
                url: `${Cypress.env('API_URL')}/api/clientdocuments`,
                body: {
                  ...params,
                },
              })
          })
        })

        cy
          .wrap(functions)
          .each((result) => {
            new Cypress.Promise((resolve, reject) => {
              result()
            })
          })
I was only warned this time, @best-flower-17510
b
Got it, It shouldn't send anymore warning messages
g
Wait, @melodic-egg-83620 you simply want to make N requests to fetch a list of PDF documents?
m
@gray-kilobyte-89541 I want to make X number of requests and assert the response.statusCode is Y, but it only fires the first request.
The number of requests could change in the future, hence why I'm making it an array of requests.
and each request is dynamically generated this way, which is easier to maintain.
g
this gives me an idea for a lesson for my paid network exercises course
in your case, you could read https://glebbahmutov.com/blog/setup-cypress-data/ since it is similar thing
m
I expect some royalties, now...
g
💸
something like this
5 Views