2017-02-27 32 views
0
componentWillMount() { 
    // redux store 
    CrudActions.getUsers(); 
} 

如何使用笑话来呼叫我的减速器?我想写的行为,而不是调用另一个CrudActions的SETALL功能测试。componentWillMount内的测试功能

到目前为止,我只能够调用componentWillMount

test('calls `componentWillMount` before rendering',() => { 
    const onWillMount = jest.fn(); 
    CrudList.prototype.componentWillMount = onWillMount; 
    mount(<CrudList />); 

    expect(onWillMount).toBeCalled(); 
}); 

回答

0

我不是100%肯定你的问题是什么在这里,所以我训释为“我怎么可以卸载我的组件,以便CrudActions.getUsers()叫做?”

安装可以调用unmount卸载它的成分(我假设你正在使用酶来安装该组件)后。

test('calls `componentWillUnmount` when unmounted',() => { 
    const onWillUnmount = jest.fn(); 
    CrudList.prototype.componentWillUnmount = onWillUnmount; 
    mount(<CrudList />).unmount(); 

    expect(onWillUnmount).toBeCalled(); 
}); 

所以叫CrudActions.getUsers()只是不假componentWillUnmount,它应该调用的实际功能。