如何仅使用jest,redux和react生成所有组件的一个快照

时间:2018-12-06 19:46:27

标签: reactjs redux jestjs enzyme

我的应用程序整个应用程序只有一页,该页面中的每个组件都由MainComponent包裹,我在项目上得到了redux,因此许多组件都是连接的组件。我想要一种方法,仅对MainComponent使用jest和酶进行快照测试,以渲染其所有子组件。我该怎么办?

第一次尝试:

...
var try1 = mount(<MainComponent customer={customer} productFilter={productFilter} />); 
// export was also set on MainComponent on this try

错误:

Invariant Violation: Could not find "store" in either the context or props of "Connect(Menu)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(Menu)".

Menu是子级连接的组件

第二次尝试:

import configureStore from 'redux-mock-store';
import store from './../../../../store';
// I also tried to use a mock of my store and the real one
...
var try2 = mount(<Provider store={store}><MainComponent customer={customer} productFilter={productFilter} /></Provider>);

错误:

The above error occurred in the <Connect(CreditDetailViewSwitcher)> component:
        in Connect(CreditDetailViewSwitcher) (at MainComponent.jsx:78)

CreditDetailViewSwitcher是另一个子级连接组件

未连接的子组件呈现完美,只有子连接的组件会引发错误

0 个答案:

没有答案