玩笑-酶测试警告:道具类型失败

问题描述 投票:0回答:1

使用jestenzyme进行测试,我认为我所做的一切都正确,但是以某种方式得到警告:

警告:道具类型失败:道具projectProjectPageUI中标记为必需,但其值为undefined。在ProjectPageUI中

这里是测试的样子:

test('shallow-render without crashing', () => {
  /*  
    project: PropTypes.object.isRequired,
   */

  const props = { 
    match: { params: {} },
  }
  const store = configureStore()(STATE_WITH_2_FAMILIES)
  shallow(<ProjectPageUIComponent store={store} {...props} />)
})

ProjectPageUI.jsx内部,我使用选择器获得了project属性:

const mapStateToProps = (state, ownProps) => ({
  project: getCurrentProject(state),
})

getCurrentProject如下:

export const getProjectsByGuid = state => state.projectsByGuid
export const getProjectGuid = state => state.currentProjectGuid

export const getCurrentProject = createSelector(
  getProjectsByGuid, getProjectGuid, (projectsByGuid, currentProjectGuid) => projectsByGuid[currentProjectGuid],
)

STATE_WITH_2_FAMILIES中,我同时定义了projectsByGuidcurrentProjectGuid,并且projectsByGuid分别具有currentProjectGuid和定义的对象的键。因此,现在我想知道为什么会发生此警告,以及应该如何更改测试,因为我希望它完全没有问题:选择器从project中获取state,应该为defined

reactjs redux enzyme jest
1个回答
0
投票

尝试使用redux Provider组件包装您的组件

shallow(
  <Provider store={store}>
    <ProjectPageUIComponent {...props} />
  </Provider>)
© www.soinside.com 2019 - 2024. All rights reserved.