【发布时间】:2022-01-05 13:03:49
【问题描述】:
我的 Cypress 测试中有以下代码部分:
cy.window()
.its('store')
.invoke('getState')
.then((state) => {
expect(state.app.gameStarted).to.equal(true)
expect(state.app.noteButtonValues).to.have.lengthOf(4);
expect(state.app.noteButtonValues).to.include(state.app.correctAnswer)
cy.get("button").contains(state.app.correctAnswer).click()
cy.window()
.its('store')
.invoke('getState')
.then((state) => {
expect(state.app.correctAnswered).to.equal(1)
expect(state.app.totalAnswered).to.equal(1)
})
})
})
我正在测试当用户点击按钮时,redux 状态也会更新。现在假设我想重复这部分点击 100 次左右。这怎么可能?
将它包装在一个 for 循环中是行不通的:
for (let i = 0; i < 100; i = i++) {
cy.window()
.its("store")
.invoke("getState")
.then((state) => {
expect(state.app.gameStarted).to.equal(true);
expect(state.app.noteButtonValues).to.have.lengthOf(4);
expect(state.app.noteButtonValues).to.include(state.app.correctAnswer);
cy.get("button").contains(state.app.correctAnswer).click();
cy.window()
.its("store")
.invoke("getState")
.then((state) => {
expect(state.app.correctAnswered).to.equal(1);
expect(state.app.totalAnswered).to.equal(1);
});
});
}
【问题讨论】:
标签: reactjs redux automated-tests cypress