2017-09-17 6 views
0

Jest로 redux 액션을 테스트하려고합니다. React Native가있는 애니메이션 라이브러리를 조롱하는 문제는 계속되고 있습니다. 여기 내 (응축) 코드입니다 : 내 테스트에서Jest - React Native Animated가있는 Redux 액션 크리에이터

// action.js 
const loginAction =() => { 
    Animated.timing(animation, { 
    toValue: 0, 
    duration: 600 
    }).start(() => { 
    dispatch({ type: 'LOGIN_SUCCESS' }); 
    }); 
} 

// mock-setup.js 
jest.mock('Animated',() => { 
    return { 
    timing: jest.fn(() => { 
     return { 
     start: jest.fn() 
     }; 
    }), 
    Value: jest.fn(() => { 
     return { 
     interpolate: jest.fn() 
     }; 
    }) 
    }; 
}); 

, 나는 발송 작업을 비교하려고 해요,하지만 난 start 함수의 콜백 내에서 이동 내 테스트를 얻을 수없는 것. 이견있는 사람?

답변

0

내 대답을 찾았습니다! 다음과 같이 필요한 내 Animated 모의은 :

jest.mock('Animated',() => { 
    return { 
    timing: jest.fn(() => { 
     return { 
     start: callback => callback() 
     }; 
    }), 
    Value: jest.fn(() => { 
     return { 
     interpolate: jest.fn() 
     }; 
    }) 
    }; 
}); 

start 함수는 함수를 통과, 그래서 난 그냥 내 조롱 버전 기능을 실행할 수있는 방법을 제공 할 필요가 있었다.

관련 문제