Skip to content

Instantly share code, notes, and snippets.

@karlAlnebratt
Forked from fredrick/App-example-test.js
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlAlnebratt/839ee23e7f6a626e91f8 to your computer and use it in GitHub Desktop.
Save karlAlnebratt/839ee23e7f6a626e91f8 to your computer and use it in GitHub Desktop.
var React = require('react/addons'),
TestUtils = React.addons.TestUtils,
TestContext = require('./TestContext'),
App = require('./App.jsx'),
app = TestContext.getRouterComponent(App);
describe('App', function() {
it('has something', function() {
expect(app.getDOMNode().textContent).toContain('something');
});
it('has nav', function() {
var nav = TestUtils.findRenderedDOMComponentWithTag(app, 'nav');
expect(nav).toBeDefined();
});
});
'use strict';
var Router = require('react-router'),
Route = Router.Route,
React = require('react/addons'),
TestUtils = React.addons.TestUtils,
TestLocation = require('react-router/modules/locations/TestLocation');
var TestContext = {
getRouterComponent: function(targetComponent) {
var component,
div = document.createElement('div'),
routes = [
React.createFactory(Route)({
name: 'test',
handler: targetComponent
})
];
TestLocation.history = ['/test'];
Router.run(routes, TestLocation, function (Handler) {
var mainComponent = React.render(React.createFactory(Handler)({}), div);
component = TestUtils.findRenderedComponentWithType(mainComponent,
targetComponent);
});
return component;
}
};
module.exports = TestContext;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment