2016-10-03 1 views
2

私は関数型propを必要とするコンポーネントを持っています。定義する関数を必要とするコンポーネントを浅くしようとしましたか?ファンクションタイプpropを酵素に定義する方法は?

handleClick: React.PropTypes.func.isRequired

これは、これは私のテスト私の酵素試験では、この機能の小道具を使用する方法

wrapper=shallow(<ConversationItem conversation={conversation1} active={true}/>); 

ある関数定義

handleClick: function(){ 
    this.props.handleClick(this.props.conversation) 
     } 

あります?

答えて

1

私はテストのためにモックを使用します。 Jest/Sinonは嘲笑している。冗談と酵素を使用して記述されたテストの例は、次のとおり

describe('Add',() => { 
    let add; 
    let onAdd; 

    beforeEach(() => { 
    onAdd = jest.fn(); 
    add = mount(<Add onAdd={onAdd} />); 
    }); 

    it('Button click calls onAdd',() => { 
    const button = add.find('button').first(); 
    const input = add.find('input').first(); 
    input.simulate('change', { target: { value: 'Name 4' } }); 
    button.simulate('click'); 
    expect(onAdd).toBeCalledWith('Name 4'); 
}); 

}); 

詳細情報はCodeMentor tutorialに見出すことができます。

関連する問題