fetchMock не реализует насмешки
У меня есть тест:
import { REQUEST_JOKES, RECEIVE_JOKES_SUCCESS } from '../types/jokes'
import { fetchJokesIfNeeded } from './jokes'
import configureStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import fetchMock from 'fetch-mock'
import expect from 'expect'
require('es6-promise').polyfill()
import 'isomorphic-fetch'
const middlewares = [thunk];
const mockStore = configureStore(middlewares)
const expectedActions = [{type: REQUEST_JOKES, quantity:1},
{type: RECEIVE_JOKES_SUCCESS, jokes:['Chuck Norris first job was as a paperboy. There were no survivors.']}];
describe('fetchJokes action', () => {
afterEach(() => {
fetchMock.restore()
fetchMock.reset()
})
it('creates RECEIVE_JOKES_SUCCESS then fetching of jokes has been done', () => {
fetchMock.getOnce('%', { body: {
"type": "success",
"value": [
{
"joke": "Chuck Norris first job was as a paperboy. There were no survivors."
}
]
}, headers: {'content-type': 'application/json'}})
const initState = {jokes:{isFetching: false, value:[]}};
const store = mockStore(initState);
return store.dispatch(fetchJokesIfNeeded(1)) // Promise
.then(() => {
expect(store.getActions()).toEqual(expectedActions)
})
})
})
npm test
возвращает что-то вроде этого:
expect(received).toEqual(expected)
Expected value to equal:
[{"quantity": 1, "type": "REQUEST_JOKES"}, {"jokes": ["Chuck Norris first job was as a paperboy. There were no survivors."], "type": "RECEIVE_JOKES_SUCCESS"}]
Received:
[{"quantity": 1, "type": "REQUEST_JOKES"}, {"jokes": ["Using his trademark roundhouse kick, Chuck Norris once made a fieldgoal in RJ Stadium in Tampa Bay from the 50 yard line of Qualcomm stadium in San Diego."], "type": "RECEIVE_JOKES_SUCCESS"}]
Очевидно, что fetchMock
не реализует извлечение насмешек в fetchJokesIfNeeded
, Следовательно, он вызывает фактический вызов извлечения. Я уже рассмотрел это средство устранения неполадок https://github.com/wheresrhys/fetch-mock/blob/master/docs/troubleshooting.md#fetch-doesnt-seem-to-be-getting-mocked устранение неисправностей.md#fetch-doesnt-seem-to-be-getting- издевались, но это не помогло.