for updateTodo, cy.wrap is only needed because of using within:
cy.wrap($todo).within( .... Usually you can just do cy.get(..).within(..) , but we are relying on the jQuery yielded by addTodo, that's why we wrap.
For getTodo, it's relying on the already wrapped jQuery/$todo, so no need to rewrap it.
It can also be explained like this, basically keeping consistent signature (cy.get vs cy.wrap(jQuery) )
:
addTodo(TODO_NAME) -> jQuery is yielded, needs wrapping
.then(updateTodo(TODO_NAME + ' new')) -> we wrap the jQuery and use within, we return a wrapped jQuery
.then(getTodoName) -> takes already wrapped jQuery and returns it
.should('equal', TODO_NAME + ' new') -> here we are still shoulding on wrapped jQuery
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Why do you use cy.wrap on updateTodo but not on getTodoName?
for updateTodo, cy.wrap is only needed because of using within:
cy.wrap($todo).within( .... Usually you can just do cy.get(..).within(..) , but we are relying on the jQuery yielded by addTodo, that's why we wrap.
For getTodo, it's relying on the already wrapped jQuery/$todo, so no need to rewrap it.
It can also be explained like this, basically keeping consistent signature (cy.get vs cy.wrap(jQuery) )
:
addTodo(TODO_NAME) -> jQuery is yielded, needs wrapping
.then(updateTodo(TODO_NAME + ' new')) -> we wrap the jQuery and use within, we return a wrapped jQuery
.then(getTodoName) -> takes already wrapped jQuery and returns it
.should('equal', TODO_NAME + ' new') -> here we are still shoulding on wrapped jQuery