Created
June 27, 2016 20:47
-
-
Save zedd45/5600828f75ecee2e0a84570bd9f9d848 to your computer and use it in GitHub Desktop.
Karma + Webpack + fetch-mock
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 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