Tests example in Readme doesn't work in 3.0.1
See original GitHub issueHello! 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)
})
})
})
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:5
Top Results From Across the Web
How can I test what my readme.md file will look like before ...
If the readme.html is in the same directory as README.md, you don't even need to serve readme.html over HTTP: you can just open...
Read more >[BUG] Autosaving response examples still does not work #511
The code example (in the README section 'Enable auto generation examples from responses') is not valid Ruby and is missing commas and has...
Read more >ReadMe: OpenAPI and Swagger for API Documentation
This guide explains: what OpenAPI and Swagger do, how to use OpenAPI spec, how to write an OpenAPI description, OpenAPI template, ...
Read more >File: README.rdoc [Ruby 3.0.0]
minitest/test is meant to have a clean implementation for language implementors that need a minimal set of methods to bootstrap a working test...
Read more >OpenSSL 3.0 - OpenSSLWiki
For example algorithms to encode and decode keys to files. If you do not load the default provider then you should always load...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@GusevDV I faced the same issue and found this solution: https://stackoverflow.com/questions/60171894/fetch-mock-dont-work-in-version-3-2-0-redux-api-middleware-test You need to add “fetch:fetch” inside the action creator.
Or set a global fetch, how we do in tests