I am following Cypress' tutorial and we are testing the "To Do" app. The test I created is supposed to delete all items from the db.json file I created, add the todo items and then finally delete all items, which are four. I added a cy.wait after each delete action. However, I am getting the following error:
Assert: expected [<li>, 3 more...]
not to exist in DOM
I was wondering if anyone know what this error means or what the issue is? This is my first time using Cypress.
describe('Smoke tests', () => {
beforeEach(() => {
cy.request('GET', '/api/todos')
.its('body')
.each(todo => cy.request('DELETE', `/api/todos/${todo.id}`))
})
context('With new todos', () => {
it.only('Save new todos', () => {
const items = [
{text: 'Buy Milk', expectedLength: 1},
{text: 'Buy Eggs', expectedLength: 2},
{text: 'Buy bread', expectedLength: 3}
]
cy.visit('/')
cy.server()
cy.route('POST', '/api/todos')
.as('create')
cy.wrap(items)
.each(todo => {
cy.focused()
.type('todo.text')
.type('{enter}')
cy.wait('@create')
cy.get('.todo-list li')
.should('have.length', todo.expectedLength)
})
})
context('With active todos', () => {
beforeEach(() => {
cy.fixture('todos')
.each(todo => {
const newTodo = Cypress._.merge(todo, {isComplete: false})
cy.request('POST', '/api/todos', newTodo)
})
cy.visit('/')
})
it('Loads existing data from DB', () => {
cy.get('.todo-list li')
.should('have.length', 4)
})
it.only('Deletes todos', () => {
cy.server()
cy.route('DELETE', '/api/todos/*')
.as('delete')
cy.get('.todo-list li')
.each($el => {
cy.wrap($el)
.find('.destroy')
.invoke('show')
.click()
cy.wait('@delete')
})
.should('not.exist')
})
})
})
})
Aucun commentaire:
Enregistrer un commentaire