Created
January 10, 2017 11:30
-
-
Save NetguruGist/6482638c061b0b8ff4c91acfc0dfab9d 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
import { fetchQuotes } from './QuotesActions.js'; | |
import configureMockStore from 'redux-mock-store'; | |
import thunk from 'redux-thunk'; | |
import fetchMock from 'fetch-mock'; | |
const mockStore = configureMockStore([thunk]); | |
describe('QuotesActions', () => { | |
afterEach(() => { | |
fetchMock.restore(); | |
}); | |
it('handles fetchQuotes success', () => { | |
const store = mockStore(); | |
fetchMock.get('/api/random-quotes', { quotes: ['hello world'] }); | |
return store.dispatch(fetchQuotes()) | |
.then(() => { | |
expect(store.getActions()).toEqual([ | |
{ type: 'FETCH_QUOTES_REQUEST' }, | |
{ type: 'FETCH_QUOTES_SUCCESS', data: ['hello world'] }, | |
]); | |
}); | |
}); | |
it('handles fetchQuotes failure', () => { | |
const store = mockStore(); | |
fetchMock.get('/api/random-quotes', 400); | |
return store.dispatch(fetchQuotes()) | |
.then(() => { | |
expect(store.getActions()).toEqual([ | |
{ type: 'FETCH_QUOTES_REQUEST' }, | |
{ type: 'FETCH_QUOTES_FAILURE' }, | |
]); | |
}); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment