- how one test can affect another test by leaving its data behind
- when and how to reset state during testing
+++
- keep
todomvc
app running - open
cypress/integration/04-reset-state/spec.js
- if you reload the test it starts failing 😕
+++
+++
+++
+++
beforeEach(() => {
cy.visit('/')
})
const addItem = text => {
cy.get('.new-todo').type(`${text}{enter}`)
}
it.only('adds two items', () => {
addItem('first item')
addItem('second item')
cy.get('li.todo').should('have.length', 2)
})
+++
- how to reset the database?
- tip we are using json-server-reset middleware
- try to reset it from command line
$ http POST :3000/reset todos:=[]
Note:
I am using httpie
to easily send the empty list to reset the database.
+++
- how to make an arbitrary cross-domain XHR request from Cypress?
- reset the database before each test
- modify
04-reset-state/spec.js
to make XHR call to reset the database - before or after
cy.visit
?
- modify
Note:
Students should modify cypress/integration/04-reset-state/spec.js
and make the request to reset the database before each test using cy.request
.
+++
- reset state before each test
- in our Best practices guide
- use
cy.request
,cy.exec
,cy.task