有人可以解释为什么我们测试异步操作吗?我们希望确保工作正常吗?
因此,在文档http://rackt.org/redux/docs/recipes/WritingTests.html中,我们模拟了服务器请求.
nock('http://example.com/')
.get('/todos')
.reply(200, { 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())
因此,我们不会测试是否与服务器联系.我们正在测试,看看响应200正确吗,是否采取了正确的行动顺序?