Skip to content

Commit

Permalink
(build) Added some tests for React components using Shallow Rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
azangru committed Sep 6, 2015
1 parent 4ce1512 commit 99c0c84
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"postcss-nested": "~1.0.0",
"postcss-normalize": "~0.1.1",
"requiredir": "^1.0.7",
"sinon": "^1.16.1",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
}
Expand Down
52 changes: 52 additions & 0 deletions frontend/tests/home/homeSpecShallow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import test from 'blue-tape';
import sinon from 'sinon';
import React from 'react/addons'; // React is required here to render Tasks
import createComponent from '../utils/create-component';
import Home from '../../src/components/home/home.jsx';

let onLogin = () => {
console.log('onlogin was called');
return true;
};

let lock = {
show(callback) {
callback();
}
};

let home = createComponent(Home, {lock: lock});

//console.log('component', home);
//console.log('method', Home.prototype);

test('Login function should call showLock function if local storage is empty', (assert) => {
global.localStorage = {getItem: function() {} };
sinon.stub(Home.prototype, 'showLock');
let mockEvent = {preventDefault: function() {
return true;
}};
Home.prototype.login(mockEvent);

assert.ok(Home.prototype.showLock.calledOnce,
'Sprint column should be a div');
Home.prototype.showLock.restore();
assert.end();
});

test('Login function should call transitionTo method local storage has token', (assert) => {
sinon.stub(Home.prototype, 'transitionTo');
let mockEvent = {preventDefault: function() {
return true;
}};
global.localStorage = {
getItem: function(string) {
return true;
}};
Home.prototype.login(mockEvent);

assert.ok(Home.prototype.transitionTo.calledOnce,
'Sprint column should be a div');
Home.prototype.transitionTo.restore();
assert.end();
});

0 comments on commit 99c0c84

Please sign in to comment.