I have a response component that calls an AJAX call in componentDidMount . While I'm trying to do this with React.addons.TestUtils , the component gets rendered without calling AJAX. How can I test a reaction component with a joke to make an AJAX call? Should I use phantomJS (or a browser like env), as well as to provide DOM capabilities to respond to the component?
Component Reaction:
return React.createClass({ componentDidMount : function() { $.ajax({ ... makes http request }) } render : function() { <div>
TestCase:
jest.dontMock(../MyComponent); var React = require('react/addons'); var TestUtils = React.addons.TestUtils; var MyComponent = require(../MyComponent); describe('Sample Test', function(){ it('To Render the component', function() { var component = <MyComponent />; var DOM = TestUtils.renderIntoDocument(component); ....
ajax unit-testing reactjs reactjs-testutils jestjs
alok mittal
source share