如何通过 Cypress 测试对 Redux 存储中的最后一个元素进行索引?
How do I index the last element in a Redux store through a Cypress test?
我想做的是检查位于 Redux 存储中某个数组的第 n 个索引处的值。
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')
})
})
每次测试运行时,它都会在聊天记录中添加一条新评论,我需要检查以确保该评论存在于 redux 中。评论将位于此处给出的数组的最后一个索引处。
cy.window().its('store').invoke('getState').its('comments').its('data')
我这辈子都想不出访问最后一个索引并检查该值是否与
.type("Where are you?")
我想你可以用“then”来做到这一点?未测试:
cy.window()
.its('store')
.invoke('getState')
.its('comments.data')
.then((data) => {
cy.wrap(data[data.length - 1])
})
.should('eq', 'Where are you?’)
我想做的是检查位于 Redux 存储中某个数组的第 n 个索引处的值。
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')
})
})
每次测试运行时,它都会在聊天记录中添加一条新评论,我需要检查以确保该评论存在于 redux 中。评论将位于此处给出的数组的最后一个索引处。
cy.window().its('store').invoke('getState').its('comments').its('data')
我这辈子都想不出访问最后一个索引并检查该值是否与
.type("Where are you?")
我想你可以用“then”来做到这一点?未测试:
cy.window()
.its('store')
.invoke('getState')
.its('comments.data')
.then((data) => {
cy.wrap(data[data.length - 1])
})
.should('eq', 'Where are you?’)