我正在测试以下传奇功能
export function* fetchMessages(channel) {
yield put(requestMessages())
const channel_name = channel.payload
try {
const response = yield call(fetch,'/api/messages/'+channel_name)
if(response.ok){
const res = yield response.json();
const date = moment().format('lll');
yield put(receiveMessages(res,channel.payload,date))
}
} catch (error){
yield put(rejectMessages(error))
}
}
这些是我对第 3 次和第 4 次产量的测试:
const gen = onFetchMessages(fetchMessages(channel))
////where export const fetchMessages = createAction(LOAD_MESSAGES);
const channel = "channel 9"
const response = []
assert.deepEqual(
gen.next(response).value,
response.json,
'should convert response to json'
)
const date = Date.now();
assert.deepEqual(
gen.next(response,channel,date).value,
put(receiveMessages(response,channel,date)),
'should dispatch LOAD_MESSAGES_SUCCESS with payloads of response, channel and date'
)
实际返回未定义,即 gen.next(response,channel,date).value 返回未定义。你能告诉我测试这些的正确方法吗?谢谢