2017-01-11 52 views
0

這太簡單了,我討厭這麼問,但是在搜索到反應路由器文檔並搜索了一遍後,我什麼也沒找到。我有一個使用withRouter包裹,當它導出的組件:在React中展開組件

export default withRouter(MyComponent) 

我想測試這個組件,但我得到了以下測試時:

<Login router={[undefined]} /> 

我通常只是導入我的組件使用酶的shallow方法單獨測試它們。有沒有辦法解開這個組件,所以我可以導入它進行測試?

+1

出口展開的一個,以及'出口{MyComponent的}' – azium

回答

1

你只需要導出組件,以及:

export const MyComponent 

,並在您的測試:

import { MyComponent } from '../src/components/MyComponent' 
+0

感謝你爲這個!我一開始沒有解構就試過,解構後我得到了它:) – Jake