2016-10-04 10 views
1

私はReduxFormを使って単体テストをしようとしていますが、このような単純なものには明らかに問題があります。ReduxFormがテストで小道具として渡されるストアが必要

実際には、検索バーがあります。入力を変更すると、そのデータを反映する状態が必要になります。

私はこのテストを書いている:

このテストする必要があり
beforeEach(() => { 
     const store = configureStore()({ 
     searchBar:{ 
      inputField:'' 
     } 
     }); 
     searchBar = TestUtils.renderIntoDocument(<SearchBar store={store}/>); 
    }); 

it('should have a form Field tag',() => { 
     const input = TestUtils.findRenderedComponentWithType(searchBar, Field); 
     expect(input).toBeTruthy(); 
    }); 

:私が合格した場合でも

Invariant Violation: Could not find "store" in either the context or props of "Connect(ConnectedField)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(ConnectedField)". in src/index.spec.js (line 3551) 

import React from 'react'; 
import { Field, reduxForm } from 'redux-form'; 
/** 
* The seach bar component class definition 
*/ 
class SearchBar extends React.Component { 
    /** 
    * Render the searchBar component 
    */ 
    render() { 
    return (
     <form> 
     <Field name="inputField" component="input" type="text"/> 
     <button type="submit">Rechercher</button> 
     </form> 
    ); 
    } 
} 

/** 
* Decorate the form 
*/ 
SearchBar = reduxForm({ 
    form: 'searchBar' 
})(SearchBar); 

export default SearchBar; 

をしかし、私は次のエラーがスローされましたそれは私のコンポーネントの小道具...(前の各呼び出しを参照してください)

アイデア

答えて

2

redux-formをテストするには、reduxストアとプロバイダが必要です。

searchBar = TestUtils.renderIntoDocument(<Provider store={store}><SearchBar /></Provider>);

はこのような何かを試してみてください

関連する問題