Skip to content

Instantly share code, notes, and snippets.

@toranb
Created June 23, 2014 21:13
Show Gist options
  • Save toranb/ad7ab373ca627e580607 to your computer and use it in GitHub Desktop.
Save toranb/ad7ab373ca627e580607 to your computer and use it in GitHub Desktop.
a very basic integration test for react (similiar to ember-testing or the angular scenario runner)
var React = require('react');
var ReactTestUtils = require('react/lib/ReactTestUtils');
var Router = require('../src/router.jsx');
var expect = require('chai').expect;
var find = require('jquery');
describe('integration like tests', function() {
var container;
beforeEach(function() {
container = document.createElement('div');
document.body.appendChild(container);
});
afterEach(function() {
document.body.removeChild(container);
});
it('should render a link for each session at boot', function (done) {
Router.renderComponent(container);
expect(2).eql(find("ul li a").length);
var first = find("ul li:eq(0) a");
expect(first.text()).eql("introduction to react");
ReactTestUtils.Simulate.click(first.get(0));
setTimeout(function() { //simulate could use a cb or promise ...
var details = find("div .Session h2").length;
expect(details).eql(1);
var name = find("div .Session h2:eq(0)").text();
expect(name).eql("Session: introduction to react");
done();
}, 0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment