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

감속기를 사용하여 감속기를 호출하려면 어떻게해야합니까? CrudActions에서 또 다른 setAll 함수를 호출하는 대신 행동 테스트를 작성하고 싶습니다.구성 요소 내 테스트 기능

지금까지 난 단지 componentWillMount

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

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

답변

0

나는 당신의 질문은 여기에 무엇을 100 % 확실하지 않다를 호출 할 수 있어요 그래서 "로 interpretting하고 어떻게 구성 요소를 마운트 해제 할 수 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 해달라고 전화를하고는 실제 함수를 호출해야합니다.