Skip to content

Tests example in Readme doesn't work in 3.0.1 #220

@GusevDV

Description

@GusevDV

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)
    })
  })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions