-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(build) Added some tests for React components using Shallow Rendering
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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(); | ||
}); |