2017-05-16 5 views
0

농담이 조롱과 얕은 렌더링 효소 사용은재귀 콜백 노드를 테스트 및/또는 모의 해보고 Jest mocking + Enzyme shallow와 함께 .querySelector를 테스트하는 방법? 다음? 테스트하거나 조롱 얼마나

onClick =() => { 
    const inputNode = this.node.querySelector('input'); 
    inputNode.click(); 
    }; 

나는 시도 :

여기
it('calls button',() => { 
    const wrapper = shallow(
    <Component />, 
); 
    const wrapperInstance = wrapper.instance(); 
    const inputNode = document.createElement('input'); 
    inputNode.value = ''; 
    const node = document.createElement('div').appendChild(inputNode); 
    wrapperInstance.node = node; 
}); 

답변

2

내가 노드를 조롱 할 방법이다.

it('calls button',() => { 
    const wrapper = shallow(
    <Component />, 
); 
    const wrapperInstance = wrapper.instance(); 
    const input = {value: 'someValue'} 
    const node = { 
    querySelector: (v) => v === 'input' ? input : null 
    } 
    wrapperInstance.node = node; 
});