【发布时间】:2021-06-13 05:05:21
【问题描述】:
在我的 E2E Cypress 测试中,我想访问被测应用程序的 Redux 存储并调度一些操作来更改一些 redux 存储值。我已经阅读了一些关于从 Cypress (https://www.cypress.io/blog/2018/11/14/testing-redux-store/) 访问 Redux 存储的博客和教程,我需要在 src/index.js 中公开应用程序存储,它应该位于应用程序包内。
供您参考,我们的“被测应用程序”和 Cypress 测试位于不同的项目结构(不同的包名称)中。
const store = createStore(reducer)
render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
)
// expose store when run in Cypress
if (window.Cypress) {
window.store = store
}
赛普拉斯是否可以访问在不同包中运行的应用程序的 redux 存储?
【问题讨论】:
-
应该可以,因为您只是将商店添加到应用程序窗口。为什么不试试看呢?