Skip to content

Commit

Permalink
add LoginLinks test
Browse files Browse the repository at this point in the history
  • Loading branch information
echenley committed Sep 14, 2015
1 parent 94e3112 commit 08985b8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/components/LoginLinks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Actions from '../actions/Actions';
const LoginLinks = React.createClass({
render() {
return (
<span>
<span className="login-links">
<a onClick={ () => Actions.showModal('login') }>Sign In</a>
<a onClick={ () => Actions.showModal('register') } className="register-link">Register</a>
</span>
Expand Down
50 changes: 50 additions & 0 deletions test/components/LoginLinks-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

import setupDOM from '../util/setup';
import createParent from '../util/createParent';
import chai, { expect } from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';

var React;
var LoginLinks;
var TestUtils;

chai.use(sinonChai);

describe('LoginLinks Component', () => {
let loginLinks;

beforeEach(() => {
setupDOM();
React = require('react/addons');
LoginLinks = require('../../src/js/components/LoginLinks');
TestUtils = React.addons.TestUtils;
});

afterEach(() => {
// React caches required modules
for (var i in require.cache) {
delete require.cache[i];
}
});

describe('DOM', function() {
beforeEach(() => {
loginLinks = TestUtils.renderIntoDocument(<LoginLinks />);
});

it('should render a span with className "login-links"', () => {
expect(loginLinks.getDOMNode().className).to.equal('login-links');
});

it('should render "Sign In" and "Register" links', () => {
let links = TestUtils.scryRenderedDOMComponentsWithTag(loginLinks, 'a');
let linkText = links.map((link) => link.getDOMNode().textContent);

expect(links.length).to.equal(2);
expect(linkText[0]).to.equal('Sign In');
expect(linkText[1]).to.equal('Register');
});
});
});

0 comments on commit 08985b8

Please sign in to comment.