Это функция, которую я пытаюсь протестировать с помощью redux-saga-test-plan
:
export function* fetchSearchMovieAsync() {
const searchInput = yield select(selectSearchInput);
if (!!searchInput && searchInput.trim() !== "") {
const task = yield fork(searchMovies, searchInput);
// cancel the pending search api call when the below action gets triggered
yield call(cancelTask, task, "CLEAR_SEARCH_COLLECTIONS");
}
}
Тест:
return expectSaga(fetchSearchMovieAsync)
.withState(state)
.provide([select(selectSearchInput), searchInput])
.fork(searchMovies, searchInput)
.call(cancelTask, task, "CLEAR_SEARCH_COLLECTIONS")
.silentRun();
Ошибка:
SagaTestError:
call expectation unmet:
Expected
--------
{ '@@redux-saga/IO': true,
combinator: false,
type: 'CALL',
payload:
{ context: null,
fn: [Function: cancelTask],
args: [ [Function: task], 'CLEAR_SEARCH_COLLECTIONS' ] } }
Actual:
------
1. { '@@redux-saga/IO': true,
combinator: false,
type: 'CALL',
payload:
{ context: null,
fn:
{ [Function: mockConstructor]
_isMockFunction: true,
getMockImplementation: [Function],
mock: [Getter/Setter],
mockClear: [Function],
mockReset: [Function],
mockRestore: [Function],
mockReturnValueOnce: [Function],
mockResolvedValueOnce: [Function],
mockRejectedValueOnce: [Function],
mockReturnValue: [Function],
mockResolvedValue: [Function],
mockRejectedValue: [Function],
mockImplementationOnce: [Function],
mockImplementation: [Function],
mockReturnThis: [Function],
mockName: [Function],
getMockName: [Function] },
args: [ 'the' ] } }
2. { '@@redux-saga/IO': true,
combinator: false,
type: 'CALL',
payload:
{ context: null,
fn: [Function: cancelTask],
args:
[ { '@@redux-saga/TASK': true,
id: 8,
meta: [Object],
isRoot: undefined,
context: {},
joiners: null,
queue: [Object],
cancel: [Function: cancel],
cont: [Function: noop],
end: [Function: end],
setContext: [Function: setContext],
toPromise: [Function: toPromise],
isRunning: [Function: isRunning],
isCancelled: [Function: isCancelled],
isAborted: [Function: isAborted],
result: [Function: result],
error: [Function: error] },
'CLEAR_SEARCH_COLLECTIONS' ] } }
3. { '@@redux-saga/IO': true,
combinator: false,
type: 'CALL',
payload:
{ context: null,
fn: { [Function: sagaWrapper] '@@redux-saga-test-plan/saga-wrapper': true },
args: [ {}, [Function: refineYieldedValue] ] } }
at new SagaTestError (node_modules/redux-saga-test-plan/lib/shared/SagaTestError.js:17:57)
at node_modules/redux-saga-test-plan/lib/expectSaga/expectations.js:67:13
at node_modules/redux-saga-test-plan/lib/expectSaga/index.js:563:7
at Array.forEach (<anonymous>)
at checkExpectations (node_modules/redux-saga-test-plan/lib/expectSaga/index.js:562:18)
at async Promise.all (index 1)
Не конечно, что я делаю неправильно здесь, в последней строке.
Примечание: это работает, когда я пытаюсь с testSaga
:
testSaga(fetchSearchMovieAsync)
.next()
.select(selectSearchInput)
.next(searchInput)
.fork(searchMovies, searchInput)
.next(task)
.call(cancelTask, task, "CLEAR_SEARCH_COLLECTIONS")
.next()
.isDone();
Был бы очень признателен, если бы кто-нибудь мог просмотреть и помогите мне здесь.