-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test examples for thunks and components
- Loading branch information
Showing
6 changed files
with
81 additions
and
4 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,17 @@ | ||
import {expect} from 'chai' | ||
import React from 'react' | ||
import {shallow} from 'enzyme' | ||
import {UserHome} from './user-home' | ||
|
||
describe('UserHome', () => { | ||
|
||
let userHome | ||
|
||
beforeEach(() => { | ||
userHome = shallow(<UserHome email={'[email protected]'} />) | ||
}) | ||
|
||
it('renders the email in an h3', () => { | ||
expect(userHome.find('h3').text()).to.be.equal('Welcome, [email protected]') | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import createHistory from 'history/createBrowserHistory'; | ||
import createMemoryHistory from 'history/createMemoryHistory' | ||
|
||
const history = createHistory(); | ||
const history = process.env.NODE_ENV === 'test' ? createMemoryHistory() : createHistory() | ||
|
||
export default history; | ||
|
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,56 @@ | ||
import {expect} from 'chai' | ||
import user, {me, logout} from './user' | ||
import axios from 'axios' | ||
import MockAdapter from 'axios-mock-adapter' | ||
import configureMockStore from 'redux-mock-store' | ||
import thunkMiddleware from 'redux-thunk' | ||
import history from '../history' | ||
|
||
const mockAxios = new MockAdapter(axios) | ||
const middlewares = [thunkMiddleware] | ||
const mockStore = configureMockStore(middlewares) | ||
|
||
describe('thunk creators', () => { | ||
|
||
let store | ||
|
||
const initialState = { | ||
user: {} | ||
} | ||
|
||
beforeEach(() => { | ||
store = mockStore(initialState) | ||
}) | ||
|
||
afterEach(() => { | ||
store.clearActions() | ||
}) | ||
|
||
describe('me', () => { | ||
it('eventually dispatches the GET USER action', () => { | ||
|
||
const fakeUser = {email: 'Cody'} | ||
mockAxios.onGet('/auth/me').replyOnce(200, fakeUser) | ||
return store.dispatch(me()) | ||
.then(() => { | ||
const actions = store.getActions() | ||
expect(actions[0].type).to.be.equal('GET_USER') | ||
expect(actions[0].user).to.be.deep.equal(fakeUser) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('logout', () => { | ||
it('logout: eventually dispatches the REMOVE_USER action', () => { | ||
const fakeUser = {email: 'Cody'} | ||
mockAxios.onPost('/auth/logout').replyOnce(204) | ||
return store.dispatch(logout()) | ||
.then(() => { | ||
const actions = store.getActions() | ||
expect(actions[0].type).to.be.equal('REMOVE_USER') | ||
expect(history.location.pathname).to.be.equal('/login') | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
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