【发布时间】:2017-08-18 08:13:36
【问题描述】:
目前可以像这样编写 reducer 和测试 saga:
// selector
const selectThingById = (state, id) => state.things[id]
// in saga
const thing = yield select(selectThingById, id)
// and test
expect(gen.next().value)
.toEqual(select(selectThingById, id))
但是我想使用更实用的方法来编写我的 reducer 并将数据(状态)放在参数的最后:
// selector
const selectThingById = R.curry((id, state) => state.things[id])
// in saga
const thing = yield select(selectThingById(id))
// test: this actually fails
expect(gen.next().value)
.toEqual(select(selectThingById(id)))
测试失败,因为selectThingById(id) 每次都创建新函数。
这可以通过将参数添加到select 而不是追加来解决。是否有可能或有什么方法可以测试这样的选择器?
【问题讨论】:
标签: javascript redux jestjs redux-saga ramda.js