2017-09-21 2 views
0

我々は、アプリケーション内の別のページにナビゲートするReactJSルータライブラリを反応させる使用が、冗談と酵素を介してユニットテストケースの実行中冗談を用いReactJSルータコンポーネントの実行中にエラー・メッセージを取得し、酵素

以下の例外を取得:

Failed context type: The context `router` is marked as required in `Switch`, but its value is `undefined`. 

Failed context type: The context `router` is marked as required in `Link`, but its value is `undefined`. 

が反応し、ルータ-DOMをから<MemoryRouter />内のコンポーネントをマウントしてくれ

+1

の場合はStackOverflowのへようこそ。私たちが助けてくれるようにしたいのであれば、私たちにいくつかの[MCVE](https://stackoverflow.com/help/mcve)を提供してください。 – DamCx

答えて

0

をご提案を送信します。このエラーは、これらのコンポーネントがRouterコンポーネントの子孫として「生きる」ことを期待している(Reactコンテキストを介してルーティング状態を取得する)ことを示しています。

mount(<MemoryRouter><YourCompThatUsesRouter /></MemoryRouter>)

は、トリックを行います。反応-ルータ-DOMから<MemoryRouter />または<BrowserRouter />のいずれかの内部

1

マウント・コンポーネントはmount()を使用して、あなたはReduxのを使用している場合も、その後<Provider /><MemoryRouter />をマウントします。

mount(
    <MemoryRouter> 
     <Component /> 
    </MemoryRouter> 
) 

またはReduxの

mount(
    <Provider store={yourDummyStore}> 
     <MemoryRouter> 
      <Component /> 
     </MemoryRouter> 
    </Provider> 
) 
関連する問題