我正在测试以下saga函数
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'
)
实际返回undefined,即gen.next(响应,通道,日期).value返回undefined。你能告诉我正确的测试方法吗?感谢
答案 0 :(得分:0)
不太确定您的代码尝试做什么。对此功能的正确测试可能如下所示:
SELECT A.EMPLOYEE, A.PHONE AS CELL, B.PHONE AS OFFICE, C.PHONE AS HOME
FROM PHONE_NUMBERS A, PHONE_NUMBERS B, PHONE_NUMBERS C
WHERE A.EMP_NUM = B.EMP_NUM
AND A.EMP_NUM = C.EMP_NUM
AND A.PHONE_TYPE = 'CELL' (+)
AND B.PHONE_TYPE = 'OFFICE' (+)
AND C.PHONE_TYPE = 'HOME' (+)