2016-09-05 4 views
1

ReactとJestで基本テストをセットアップしました。それは何らかの理由で失敗するようです。ReactとJestによる基本テストのトラブルシュー

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import TestUtils from 'react-addons-test-utils'; 
// import App from '../src/client/app.jsx'; 

const App = (props) => (
    <div>Hello world</div> 
); 

it('App renders hello world',() => { 
    const app1 = TestUtils.renderIntoDocument(<App />); 
    const appNode = ReactDOM.findDOMNode(app1); 
    console.log(app1, appNode); 
    expect(appNode.textContent).toEqual('Hello world'); 
}); 

コンソールに印刷すると、app1とappNodeの両方がnullになります。どんな助け?以下

スクリーンショット:

enter image description here

答えて

2

TestUtils and React Stateless Components

示唆溶液は、DIVのような別の コンポーネントの内部構成要素をラップすることです。

const app1 = TestUtils.renderIntoDocument(<div><App /></div>); // this should work 
+0

ありがとうございます。出来た! – vijayst