Last active
August 29, 2015 14:22
-
-
Save karlbright/00448bca3f8645fc66bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jest.dontMock('../'); | |
function noop() {} | |
describe('React Router Context Test', function() { | |
var React, Router, TestUtils, stubContext, TestHandler; | |
beforeEach(function() { | |
React = require.requireActual('react/addons'); | |
TestUtils = React.addons.TestUtils; | |
stubContext = require.requireActual('react-stub-context'); | |
TestHandler = require('..'); | |
Router = function() {} | |
}); | |
it('has context correctly', function() { | |
Router.makeHref = noop; | |
Router.isActive = noop; | |
TestHandler = stubContext(TestHandler, { router: Router }); | |
var render = TestUtils.renderIntoDocument(React.createElement(TestHandler, {})); | |
var link = TestUtils.findRenderedDOMComponentWithTag(render, 'a'); | |
expect(link).toBeDefined(); | |
expect(link.getDOMNode().innerHTML).toEqual('foo'); | |
TestUtils.Simulate.click(link); | |
expect(link.getDOMNode().innerHTML).toEqual('bar'); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require('react'); | |
var Router = require('react-router'); | |
var Link = Router.Link; | |
var TestHandler = React.createClass({ | |
getInitialState: function() { | |
return { | |
text: 'foo' | |
} | |
}, | |
changeText: function() { | |
this.setState({ text: 'bar' }); | |
}, | |
render: function() { | |
return React.createElement(Link, { | |
to: 'home', | |
onClick: this.changeText | |
}, this.state.text); | |
} | |
}); | |
module.exports = TestHandler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment