使用 React 和 Jest 解决基本测试问题
Trouble-shooting a basic test with React and 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。有帮助吗?
截图如下:
TestUtils and React Stateless Components:
the suggested solution is to wrap the component inside of another
component such as a DIV.
const app1 = TestUtils.renderIntoDocument(<div><App /></div>); // this should work
我已经用 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。有帮助吗?
截图如下:
TestUtils and React Stateless Components:
the suggested solution is to wrap the component inside of another component such as a DIV.
const app1 = TestUtils.renderIntoDocument(<div><App /></div>); // this should work