-
Notifications
You must be signed in to change notification settings - Fork 194
Closed
Description
Hello!
Test example in Readme doesn't work for me in redux-api-middleware 3.0.1. FetchMock not mocking request and server send real response. I tried to run the test in version 2.3.0 and the request was mocked.
How to fix it in version 3.0.1?
import configureMockStore from "redux-mock-store"
import { apiMiddleware } from "redux-api-middleware"
import thunk from "redux-thunk"
import fetchMock from "fetch-mock"
import {getUser} from "./user"
const middlewares = [ thunk, apiMiddleware ]
const mockStore = configureMockStore(middlewares)
describe("async user actions", () => {
afterEach(() => {
fetchMock.reset()
fetchMock.restore()
})
it("should dispatch USER_SUCCESS when getUser is called", () => {
const store = mockStore({});
const body = {
email: "EMAIL",
username: "USERNAME"
}
//fetchMock doesn't work in 3.0.1
fetchMock.getOnce("https://hostname/api/users/", {body: body, headers: {"content-type": "application/json"}})
const expectedActions = [
{type: actions.USER_REQUEST},
{type: actions.USER_SUCCESS, payload: body}
]
return store.dispatch(actions.getUser()).then(() => {
expect(store.getActions()).toEqual(expectedActions)
})
})
})
valmassoi, zaknafain, boro28, sylsmolen and GusevDV
Metadata
Metadata
Assignees
Labels
No labels