1

What I'm trying to do is check for a value that is located at the nth index of some array in a Redux store.

    it('Enter text into comments, send comment, verify comment is displayed in comment list', ()=>{
        cy.server()
        cy.get('#call-input').type("Where are you?")
        cy.get('#send-btn').click()
        cy.route('POST', '/api/1/call/chatlog/1001/comment').as('sendComment')
        cy.window().its('store').invoke('getState').its('comments').its('data')

    })

})

Every time the test runs it will add a new comment to a chat log and I need to check to make sure that comment exists in redux. The comment will be located at the very last index of the array give here.

        cy.window().its('store').invoke('getState').its('comments').its('data')

I just can't for the life of me figure out out to access the last index and check if the value matches the

.type("Where are you?")
Heyrio
  • 129
  • 2
  • 11

1 Answers1

2

I think you can do this using ”then”? Untested:

 cy.window()
    .its('store')
    .invoke('getState')
    .its('comments.data')
    .then((data) => {
       cy.wrap(data[data.length - 1])
    })
    .should('eq', 'Where are you?’)
Reece Casey
  • 154
  • 5