我是React以及Jest的全新品牌,我认为我有一个相当简单的组件,但我一直收到这个错误,我在GitHub的问题上没有看到任何关于它的信息,只有一个特定的React,而不是Jest,问题这里。完整错误是:TypeError: Object <UserInfo /> has no method 'mountComponentIntoNode'
反应代码
/** @jsx React.DOM */
var React = require('react');
var Router = require('react-nested-router');
var user = require('../lib/stores/user');
/**
* UserInfo
*
* Form for user's personal information.
**/
var UserInfo = React.createClass({
handleSubmit: function(event) {
event.preventDefault();
user.firstName = this.refs.firstName.getDOMNode().value;
user.lastName = this.refs.lastName.getDOMNode().value;
user.dateOfBirth = this.refs.dob.getDOMNode().value;
user.ssn = this.refs.ssn.getDOMNode().value;
Router.transitionTo('/contact-info');
},
render: function() {
return (
<section>
<form onSubmit={this.handleSubmit}>
<label class="first-name-label" htmlFor="first-name">First Name</label>
... lots of inputs and labels ...
</form>
</section>
);
}
});
module.exports = UserInfo;
Jest Code
/** @jsx React.DOM */
jest.dontMock('../application/views/user-info.jsx');
var React = require('react/addons');
var UserInfo = require('../application/views/user-info.jsx');
var TestUtils = React.addons.TestUtils;
describe('UserInfo', function () {
it('example test only', function () {
var userinfo = '<UserInfo />'
TestUtils.renderIntoDocument(userinfo);
});
});
答案 0 :(得分:1)
啊!我想我终于明白了。我意外地在一个字符串中有<UserInfo />
!
describe('UserInfo', function () {
it('example test only', function () {
var userinfo = <UserInfo />
TestUtils.renderIntoDocument(userinfo);
});
});
以上作品!