DEV Community

Discussion on: Functional Programming Test Patterns with Cypress

Collapse
 
muratkeremozcan profile image
Murat K Ozcan • Edited

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