你好了Redux文檔中測試他們有這樣的例子來測試API調用:測試愛可信與興農要求,與終極版和噶
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import * as actions from '../../actions/counter'
import * as types from '../../constants/ActionTypes'
import nock from 'nock'
const middlewares = [ thunk ]
const mockStore = configureMockStore(middlewares)
describe('async actions',() => {
afterEach(() => {
nock.cleanAll()
})
it('creates FETCH_TODOS_SUCCESS when fetching todos has been done', (done) => {
nock('http://example.com/')
.get('/todos')
.reply(200, { body: { todos: ['do something'] }})
const expectedActions = [
{ type: types.FETCH_TODOS_REQUEST },
{ type: types.FETCH_TODOS_SUCCESS, body: { todos: ['do something'] } }
]
const store = mockStore({ todos: [] }, expectedActions, done)
store.dispatch(actions.fetchTodos())
})
})
我使用的是業力測試環境,我想我可以不要用諾克來測試這個。所以我正在考慮用Sinon來測試它。麻煩是我不明白我將如何測試使用這個,因爲我沒有傳遞迴調到我的API函數調用。我使用axios來調用我的外部API。
對此有什麼更新?你設法解決它嗎? – anoop