我有以下的传奇故事,它们监听着不同类型的action
:
export default function *() {
yield takeEvery('FOO', listener)
yield takeEvery('BAR', listener2)
yield takeEvery('HELLO_WORLD', listener3)
}
从本质上讲,这个传奇故事在收到某些动作时会具有多种行为。
如果将FOO
作为操作类型,它将调用listener
函数,等等。
此刻,我很难开玩笑地仅在这3行中编写测试报道。
我以为可以写点东西,但是没有运气:
describe('for action type that has "FOO"', () => {
const actionPayload = {
type: 'FOO',
}
const gen = saga({ type: actionPayload })
it('listens to "FOO" and yield action', () => {
const actual = gen.next()
const expected = takeEvery('FOO', listener)
expect(actual.value).toEqual(expected)
})
})
我想念什么?
答案 0 :(得分:1)
takeEvery
实际上是fork
。因此,您应该像这样进行测试:
describe('for action type that has "SMS_API_REQUEST"', () => {
const actionPayload = {
type: 'FOO',
}
const gen = saga({ type: actionPayload })
it('listens to "FOO" and yield action', () => {
const actual = gen.next()
const expected = fork(takeEvery, 'FOO', listener)
expect(actual.value).toEqual(expected)
})
})