Redux的
我这样配置存储:
ReactDOM.render(
<CookiesProvider>
<Provider store={store}>
<App />
</Provider>
</CookiesProvider>,
document.getElementById('root'),
)
if (window.Cypress) {
window.Cypress.store = store
}
我想检查以下值是否存在。在redux中:store=>store.auth.user.account.person.email,值是一个字符串,一个电子邮件地址。
我正在尝试以下测试:
it.only('checks if email is being shown', () => {
cy.get('.email-button')
.should(() => {
Cypress.store.getState().then(state => {
console.log("state", state);
expect(state.auth.user.account.person.email).to.equal('asfasdf')
})
})
})
但它失败了,出现了以下错误:
Timed out retrying after 4000ms: Cypress.store.getState(...).then is not a function
40 | cy.get('.contact-button.email')
41 | .should(() => {
> 42 | Cypress.store.getState().then(state => {
| ^
43 | console.log("state", state);
44 | expect(state.token).to.equal('asfasdf')
45 | })
我该怎么修?我做错了什么?
store.getState()
是一个同步函数。它不会回报承诺。试试这样的东西:
it.only('checks if email is being shown', () => {
cy.get('.email-button')
.should(() => {
const state = Cypress.store.getState();
expect(state.auth.user.account.person.email).to.equal('asfasdf');
})
})