We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I want to test the following saga:
function* fetchCustomerById({ id }) { try { const fetchedCustomer = yield call(rest.getCustomerById, id); if (fetchedCustomer) { yield put(fetchCustomerSuccess(fetchedCustomer)); } } catch (error) { yield put(fetchError(error)); } }
I'm trying this:
it('testing fetchCustomerById', () => { const id = '123'; const saga = testSaga(tests.fetchCustomerById, id); saga .next() .call(rest.getCustomerById, undefined) .next(true) .put(fetchCustomerSuccess(undefined)) .next() .isDone(); });
And the test doesn't pass. Got this error: Assertion 2 failed: put effects do not match
Expected -------- { '@@redux-saga/IO': true, combinator: false, type: 'PUT', payload: { channel: undefined, action: { type: 'FETCH_CUSTOMER_SUCCESS', payload: undefined } } } Actual ------ { '@@redux-saga/IO': true, combinator: false, type: 'PUT', payload: { channel: undefined, action: { type: 'FETCH_CUSTOMER_SUCCESS', payload: true } } } 50 | .call(rest.getCustomerById, undefined) 51 | .next(true) > 52 | .put(fetchCustomerSuccess(undefined)) | ^ 53 | .next() 54 | .isDone(); 55 | }); at assertSameEffect (node_modules/redux-saga-test-plan/lib/testSaga/assertSameEffect.js:18:11) at Object.put (node_modules/redux-saga-test-plan/lib/testSaga/index.js:49:37) at Object.<anonymous> (src/appRedux/sagas/iObserverSagas/CustomerSaga.test.js:52:8)
Is there a way to pass undefined payload?
Thanks, Georgi
The text was updated successfully, but these errors were encountered:
You can mock call(rest.getCustomerById, id). Heres the test code I would write. (Not tested).
call(rest.getCustomerById, id)
import {expectSaga} from 'redux-saga-test-plan'; import {call} from 'redux-saga-test-plan/matchers'; test('fetchCustomerById', () => expectSaga(fetchSaga) .provide([[call.fn(rest.getCustomerById), true]]) .put(fetchCustomerSuccess(expectedCustomer) .dispatch(action.fetchCustomerById()) .silentRun());
In the test, reset.getcustomerById would return true. Read more about static providers on document
Sorry, something went wrong.
No branches or pull requests
I want to test the following saga:
I'm trying this:
And the test doesn't pass. Got this error:
Assertion 2 failed: put effects do not match
Is there a way to pass undefined payload?
Thanks,
Georgi
The text was updated successfully, but these errors were encountered: