Reactjs cypress react单元测试:嵌套组件上的断言';使用状态

Reactjs cypress react单元测试:嵌套组件上的断言';使用状态,reactjs,unit-testing,testing,cypress,Reactjs,Unit Testing,Testing,Cypress,只是简单介绍一下使用Cypress进行单元测试,我想知道如何检查React功能组件的状态,这些组件需要封装在一堆提供程序中(用于redux、主题、上下文等) 首先,我创建了一个自定义的挂载: export function mountWithProviders( component, { initialState = {}, route = '/', history = createMemoryHistory({ initialEntries: [route] }), ...option

只是简单介绍一下使用Cypress进行单元测试,我想知道如何检查React功能组件的状态,这些组件需要封装在一堆提供程序中(用于redux、主题、上下文等)

首先,我创建了一个自定义的
挂载

export function mountWithProviders(
  component,
  { initialState = {}, route = '/', history = createMemoryHistory({ initialEntries: [route] }), ...options } = {}
) {
  const store = createStore(rootReducer, initialState, applyMiddleware(thunk));
  return {
    ...mount(
      <Provider store={store}>
        <MuiThemeProvider theme={theme}>
          <ThemeProvider theme={theme}>
            <TContextProvider>
              <Router history={history}>{component}</Router>
            </TContextProvider>
          </ThemeProvider>
        </MuiThemeProvider>
      </Provider>,
      { ...options }
    )
  };
}
导出函数mountWithProviders(
组成部分,
{initialState={},route='/',history=createMemoryHistory({initialEntries:[route]}),…options}={}
) {
const store=createStore(rootReducer、initialState、applyMiddleware(thunk));
返回{
…坐骑(
{component}
,
{…选项}
)
};
}
不确定我是否需要所有这些,还没有弄清楚,但至少需要Redux和主题提供程序,否则测试就会崩溃

因此,在我的单元测试中,我以这种方式安装我的组件:

mountWithProviders(<MyComp props={mockProps} />);
mountWithProviders();
因此,装入的最外层组件是
Provider
,而
MyComp
是深度嵌套的

是否有一种方法可以访问和检查
useState
hook内
MyComp
的状态

我看到过以下例子:
cy.window().should('have.property','mycomp')。其('state')
等。。。。。 但我不太理解它,无法复制