I am trying to write a simple test. I have Karma as the test runner and Mocha as the framework.
Each time I run the test, it fails with the error...
TypeError: h1.findDOMNode is not a function
Here's the test script...
// Article-test.jsx
var React = require('react'),
TestUtils = require('react-addons-test-utils'),
expect = require('expect'),
Article = require('../Article.jsx');
it("renders an h1", function () {
var article = TestUtils.renderIntoDocument(
<Article />
);
var h1 = TestUtils.findRenderedDOMComponentWithTag(
article, 'h1'
);
expect(h1.findDOMNode().textContent).toEqual("Example Title");
});
This was after finding that getDOMNode
is deprecated, and is now findDOMNode
. I keep finding out methods which have been deprecated.
react + react-addons-test-utils ver. 15.0.1 | mocha ver. 2.4.5
Try
expect(h1.textContent).toEqual("Example Title");