vendredi 25 septembre 2020

Understanding then() in Cypress

I am reading through the documentation in Cypress and I think I have an idea as to what then() does. It works like promises, where a promise returns another promise, but with then(), we are returning a new subject.

If we look at the code example below, we are using then() because we are returning a new variable, which in this case is called target.

Am I understanding this correctly? If not, can someone correct me?

  it.only('Marks an incomplete item complete', () => {
         //we'll need a route to stub the api call that updates our item
         cy.fixture('todos')
         .then(todos => {
             //target is a single todo, taken from the head of the array. We can use this to define our route
             const target = Cypress._.head(todos)
             cy.route(
                 "PUT",
                 `api/todos/${target.id}`,
                 //Here we are mergin original item with an object literal 
                 Cypress._.merge(target, {isComplete: true})
             )
         })

Aucun commentaire:

Enregistrer un commentaire