【发布时间】:2016-04-03 14:53:02
【问题描述】:
有人能解释一下我们为什么要测试异步操作吗?我们希望确保什么有效?
所以在文档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 正确的响应?
【问题讨论】:
-
测试你认为什么是重要的。该指南只是试图展示什么是可能的。
标签: javascript unit-testing reactjs redux