Skip to content

Instantly share code, notes, and snippets.

@NetguruGist
Created January 10, 2017 11:30
Show Gist options
  • Save NetguruGist/6482638c061b0b8ff4c91acfc0dfab9d to your computer and use it in GitHub Desktop.
Save NetguruGist/6482638c061b0b8ff4c91acfc0dfab9d to your computer and use it in GitHub Desktop.
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