Skip to content

Instantly share code, notes, and snippets.

@zedd45
Created June 27, 2016 20:47
Show Gist options
  • Save zedd45/5600828f75ecee2e0a84570bd9f9d848 to your computer and use it in GitHub Desktop.
Save zedd45/5600828f75ecee2e0a84570bd9f9d848 to your computer and use it in GitHub Desktop.
Karma + Webpack + fetch-mock
import configureMockStore from 'redux-mock-store';
import * from '../actions';
// must come before fetch-mock
import 'isomorphic-fetch';
import fetchMock from 'fetch-mock';
import thunk from 'redux-thunk';
const expect = chai.expect;
const fixtureData = require('aFixtureFile');
const mock = fetchMock.mock;
const middlewares = [ thunk ];
const mockStore = configureMockStore(middlewares);
describe('Actions: fetchEvents', function () {
beforeEach(function () {
mock(/^\/api\/events/, fixtureData);
});
afterEach(function () {
mock.restore();
});
it('creates EVENTS_SUCCESS when fetching is successful', function () {
const store = mockStore({ events: { list: [] }});
const expectedActions = [
{ type: EVENTS_REQUESTED },
{ type: EVENTS_SUCCESS },
];
return store.dispatch(fetchEvents())
.then(function () {
debugger;
expect(store.getActions()).to.equal(expectedActions);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment