Created
January 29, 2018 09:09
-
-
Save abruzzi/596a8e4e2f0293a793e69a0feb1b33d6 to your computer and use it in GitHub Desktop.
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
export const getCollections = () => { | |
return (dispatch, getState) => { | |
const state = getState() | |
const params = { | |
priceLow: state.sidebar.lowPrice, | |
priceHigh: state.sidebar.highPrice | |
} | |
dispatch({ | |
type: COLLECTION, | |
payload: axios.get(`http://localhost:3000/api/collections`, {params}) | |
}) | |
} | |
} |
Author
abruzzi
commented
Jan 30, 2018
import axios from 'axios'
import {getCollections} from './actions'
import {COLLECTION_PENDING, COLLECTION_FULFILLED, COLLECTION_REJECTED} from './types'
import store, {mockStore} from './mockStore'
describe('fetch data', () => {
afterEach(() => {
store.clearActions()
})
it('fetch data async successfully', () => {
const data = []
axios.get = jest.fn().mockImplementation(() => Promise.resolve(data))
const testState = {
home: {
collections: [],
loading: false
},
sidebar: {
lowPrice: 100,
highPrice: 200
}
};
const mocked = mockStore(testState)
const expectedActions = [
{type: COLLECTION_PENDING},
{type: COLLECTION_FULFILLED, payload: {data}}
]
return mocked.dispatch(getCollections()).then(() => {
expect(mocked.getActions()).toEqual(expectedActions)
})
})
})
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment